The purpose of this document is twofold:
Being terribly inconsistent, the guidelines are not set in stone and if you have a good argument for doing things a particular, I don't really care.
BUT first and foremost, code must comply with PEP8 first. This is easy to automate. I like black since it's easy to use but there' plenty of advanced linters out there.
I usually invoke it like this to turn off forcing double quotes and force the line length to 72:
black -S -l 72 file.py
That aside, I have the following idiosyncracies:
This is really just because I like how C does it. And Cpython's C-based so why not?
Like so:
= "This is a phrase"
string = "word"
word = 'a'
cur_char = '\n' # note, two characters, but it's still ONE char out
newline # keys are single-quoted to avoid confusion
= { 'key' "1245dqw3w431", 'return': newline } dictionary
The only exception is for strings with quotes in them (anything to avoid escapes, really)
= (
quoted_string '"You miss 100% of the shots you don't take - Wayne Gretsky"'
' - Michael Scott'
)
That brings me to my next point.
As in:
= (
longboi "This is a really long string usefull when making help menus. Be\n"
"sure to leave s space at the end of each line, or add a new line\n"
"when needed.\n\n"
"Try your best to keep formatting accurate like this."
)
Again, see PEP8.
It's a pain to read:
1/(2*sqrt(pi))*exp(x**2)
Do this
1 / (2 * sqrt(pi)) * exp(x ** 2)
The same goes for logic operators
& false ^ true true
This is python. Unless there's a compatibility thing (like a library's code was written that way, or it matches an API variable), snake_case is preferred.
= int(input()) # variable
user_input = 1000 # constant
MAX_INPUT def judge_input(_input, _max): # function
if _max > _input:
print("Too big!")
judge_input(user_input, MAX_INPUTclass Input_Judger: # a class
# etc etc
Example exception:
# this doesn't actually work, but you get the idea
= requests.get("www.debian.org")
r = r.json()['pageSize'] # camel case ok pageSize