error={"status":400,"error":"images should be in uri format(http://img.png)"}
Considerations:
4 spaces indentation.
Closing bracket at the same level of indentation of the line containing the opening bracket.
Name, 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 with err, 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.
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 ?
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:
The main reason to standardize on a single form of quotes is aesthetics. Having one kind of quotes everywhere reduces reader distraction. It will also enable a future version of Black to merge consecutive string literals that ended up on the same line (see #26 for details).
Why settle on double quotes? They anticipate apostrophes in English text. They match the docstring standard described in PEP 257. An empty string in double quotes ("") is impossible to confuse with a one double-quote regardless of fonts and syntax highlighting used. On top of this, double quotes for strings are consistent with C which Python interacts a lot with.
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.
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.
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...
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
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!
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