indentation

What is the proper way to format a multi-line dict in Python?

徘徊边缘 提交于 2019-11-27 06:03:24
In Python, I want to write a multi-line dict in my code. There are a couple of ways one could format it. Here are a few that I could think of: mydict = { "key1": 1, "key2": 2, "key3": 3, } mydict = { "key1": 1, "key2": 2, "key3": 3, } mydict = { "key1": 1, "key2": 2, "key3": 3, } I know that any of the above is syntactically correct, but I assume that there is one preferred indentation and line-break style for Python dicts. What is it? Note: This is not an issue of syntax. All of the above are (as far as I know) valid Python statements and are equivalent to each other. I use #3. Same for long

How do I tidy up an HTML file's indentation in VI?

强颜欢笑 提交于 2019-11-27 05:51:19
How do I fix the indentation of his huge html files which was all messed up? I tried the usual "gg=G" command , which is what I use to fix the indentation of code files. However, it didn't seem to work right on HTML files. It simply removed all the formatting. I also tried setting :filetype = xml , to see if tricking it into thinking this was an XML file would help but it still didn't do it. marcog With filetype indent on inside my .vimrc , Vim indents HTML files quite nicely. Simple example with a shiftwidth of 2: <html> <body> <p> text </p> </body> </html> There's several things that all

How to fix/convert space indentation in Sublime Text?

只谈情不闲聊 提交于 2019-11-27 05:45:12
Example: If I have a document with 2 space indentation, and I want it to have 4 space indentation, how do I automatically convert it by using the Sublime Text editor? Here's a neat trick in Sublime Text 2 or 3 to convert your indentation spacing in a document. TL;DR: Converting from 2 spaces to 4 spaces: Ensure tab width is set to 2. Convert your 2-space indentation to tabs, switch to tab width 4, and then convert the indentation back to spaces. The detailed description: Go to: View -> Indentation It should read: Indent using spaces [x] Tab width: 2 Select: Convert Indentation to Tabs Then

Inconsistent use of tabs and spaces in indentation

廉价感情. 提交于 2019-11-27 05:17:18
def contains_sequence(dna1, dna2): ''' (str, str) -> bool Return True if and only if DNA sequence dna2 occurs in the DNA sequence dna1. >>> contains_sequence('ATCGGC', 'GG') True >>> contains_sequence('ATCGGC', 'GT') False ''' b=False len2=len(dna2) i=0 for j in dna1: temp=dna1[i:i+len2] if temp == dna2: b=True i=i+1 return b I am new to Python. The program pasted above gives me an error "Inconsistent use of tabs and spaces in indentation" at line "if temp == dna2:" specifically. Can someone please help me out in finding out how the indentation is incorrect? It means you have mixed up spaces

Xcode: Adjusting indentation of auto-generated braces?

浪子不回头ぞ 提交于 2019-11-27 05:12:36
问题 Code auto-generated by Xcode seems to have the opening brace on the same line by default: @interface Controller : NSObject { } I'd like the opening brace on a line of its own, like this: @interface Controller : NSObject { } This applies in general to any method / class auto-generated by Xcode. In Xcode preferences I have "Indent solo { by" set to 0: How can I fix this? 回答1: For Xcode 3.x, you can use the following: If you open up a terminal session and enter defaults write com.apple.Xcode

Copy-paste into Python interactive interpreter and indentation

懵懂的女人 提交于 2019-11-27 04:33:21
问题 This piece of code, test.py: if 1: print "foo" print "bar" can be succesfully executed with execfile("test.py") or python test.py , but when one tries to copy-paste it into python interpreter: File "<stdin>", line 3 print "bar" ^ SyntaxError: invalid syntax Why is it so? Can interpreter by configured in such a way that it would read copy-pasted text succesfully? I guess that may affect typing in the interpreter, but that's ok for me. 回答1: Indentation is probably lost or broken. Have a look at

Indenting #defines

泄露秘密 提交于 2019-11-27 03:22:14
I know that #define s, etc. are normally never indented. Why? I'm working in some code at the moment which has a horrible mixture of #define s, #ifdef s, #else s, #endif s, etc. All these often mixed in with normal C code. The non-indenting of the #define s makes them hard to read. And the mixture of indented code with non-indented #define s is a nightmare. What is the benefit of not indenting #define s? Does it make me a bad person if I indent them? Isn't this much nicer? #ifdef SDCC #if DEBUGGING == 1 #if defined (pic18f2480) #define FLASH_MEMORY_END 0x3DC0 #elif defined (pic18f2580) #define

IndentationError: unexpected indent error

空扰寡人 提交于 2019-11-27 03:10:27
问题 I am new to Python and am getting this error: Traceback (most recent call last): File "/usr/local/bin/scrapy", line 4, in <module> execute() File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/cmdline.py", line 130, in execute _run_print_help(parser, _run_command, cmd, args, opts) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy/cmdline.py", line 96, in _run_print_help func(*a, **kw) File "

“Expected an indented block” error?

假如想象 提交于 2019-11-27 03:09:07
问题 I can't understand why python gives an "Expected indentation block" error? """ This module prints all the items within a list""" def print_lol(the_list): """ The following for loop iterates over every item in the list and checks whether the list item is another list or not. in case the list item is another list it recalls the function else it prints the ist item""" for each_item in the_list: if isinstance(each_item, list): print_lol(each_item) else: print(each_item) 回答1: You have to indent

How to write an empty indentation block in Python?

好久不见. 提交于 2019-11-27 03:01:53
问题 The runtime keeps telling me: expected an indented block But I don't want write nothing inside my except block, I just want it to catch and swallow the exception. 回答1: Just write pass as in try: # Do something illegal. ... except: # Pretend nothing happened. pass EDIT: @swillden brings up a good point, viz., this is a terrible idea in general. You should, at the least, say except TypeError, DivideByZeroError: or whatever kinds of errors you want to handle. Otherwise you can mask bigger