If you write Python and don't know what PEP8 is go and check it now.
PEP8 is the style guide for Python code and I think is quite good and I very ...
For further actions, you may consider blocking this person and/or reporting abuse
Yeah, PEP8 is a little limited. Fortunately there are automated ways to go beyond that.
My favorite tool is black. I think it's better than the pep8 formatter (which as you highlighted is limited) and yapf (which is sometimes weird).
You can integrate it with pretty much any tool (editor, CI, git hooks...) and forget about most of those issues. Give it a try!
Worst disadvantage of black? It forces double quotes on you unless you disable quote management altogether.
Surrender to the robots :-)
Prettier for JS defaults to double quotes
Rubocop for Ruby defaults to double quotes
black for Python defaults to double quotes and gives a good reason for it:
Rubocop defaults to single quotes because double quotes do more escaping and interpolation.
docs.rubocop.org/en/latest/cops_st...
Thanks Clayton, I remembered it wrongly!
I didn't know... Will take a look into it.. even if it enforces double quotes... hahahaha
Does this apply to string literals?
lets say you have long strings like
I would write that as:
Considerations:
err_obj
, everything in Python is an object, naming an object "object" does not explains what's the intention or meaning, like naming a view "view" or class "class". So that lefts us witherr
, and is not much to ask to write a full world: "err" -> "error", specially if this one is short.Remember we think we are most of the time power typing, but that's not true, in reality most of the time we are reading code, staring into the abyss. Make your code clear, explicit, avoid useless redundancy and don't leave chance for miss interpretation.
Thanks I'll make changes to my code.
However, I was asking if you have a really long string e.g. my error object, or a regex string. Is there a way to handle exceptionally long strings without using
\
newline ?Yes, you can do something like....
Or use multi-line strings, but usually they are inconvenient because they will get the spaces from the indentation.
But keep in mind that this is about taste mostly and subjective, so do what ever you feel fits you and your team...
I agree
That's some general good style practice, but I'm going to have to disagree on the mega long import. What's wrong with just importing the module you want to use (from django.db.models import expressions)? That way you can more easily avoid name clashes.
I'm fine also with that... this was just to illustrate
Recently I was writing a contributing guide for a medium project of my work. There are some Python newbies (I consider myself a newbie as well), and I need explain them some coding guidelines. Definitely I will send them this article. Greetings from Holguín, Cuba.
A pleasure Ozkar, long time didn't know about you!