“assert” statement with or without parentheses

The last assert would have given you a warning (SyntaxWarning: assertion is always true, perhaps remove parentheses?) if you ran it through a full interpreter, not through IDLE. Because assert is a keyword and not a function, you are actually passing in a tuple as the first argument and leaving off the second argument. Recall … Read more

Chained method calls indentation style in Python [duplicate]

This is a case where a line continuation character is preferred to open parentheses. ShortName.objects.distinct() \ .filter().values() # looks better The need for this style becomes more obvious as method names get longer and as methods start taking arguments: return some_collection.get_objects(locator=l5) \ .get_distinct(case_insensitive=True) \ .filter(predicate=query(q5)) \ .values() PEP 8 is intend to be interpreted with … Read more

Why does Python pep-8 strongly recommend spaces over tabs for indentation? [closed]

Well well, seems like everybody is strongly biased towards spaces. I use tabs exclusively. I know very well why. Tabs are actually a cool invention, that came after spaces. It allows you to indent without pushing space millions of times or using a fake tab (that produces spaces). I really don’t get why everybody is … Read more

What’s the correct way to sort Python `import x` and `from x import y` statements?

Imports are generally sorted alphabetically and described in various places besides PEP 8. Alphabetically sorted modules are quicker to read and searchable. After all, Python is all about readability. Also, it is easier to verify that something is imported, and avoids duplicate imports. There is nothing available in PEP 8 regarding sorting. So it’s all … Read more

How to write very long string that conforms with PEP8 and prevent E501 [duplicate]

Since neighboring string constants are automatically concatenated, you can code it like this: s = (“this is my really, really, really, really, really, really, ” “really long string that I’d like to shorten.”) Note no plus sign, and I added the extra comma and space that follows the formatting of your example. Personally I don’t … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)