Skip to content

Instantly share code, notes, and snippets.

@dcramer
Last active June 1, 2021 14:28
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save dcramer/5094200 to your computer and use it in GitHub Desktop.
Save dcramer/5094200 to your computer and use it in GitHub Desktop.
Python Standards (that I would change and enforce if I could)
# dont do this
this_function_name(foo, bar
baz)
# do this
cramers_version(
foo, bar, baz)
# allow this
cramers_version(foo, bar,
baz)
# do this
foo(
'bar',
keyword='argument',
)
# dont do this
foo(hello='world', biz='baz',
foo='bar')
# do this
foo(
hello='world',
biz='baz',
foo='bar',
)
# dont do this
def my_func():
"""lol this is bad"""
# dont do this
def my_func():
"lol this is bad"
# dont do this
def my_func():
"""lol this is bad
but worse
"""
# cramer's version
def my_func():
"""
lol this is readable
no matter how many lines it is
"""
# dont do this
foo = {
'foo': 'bar',
'baz': 'biz'}
# do this
foo = {
'foo': 'bar',
'baz': 'biz', # always have a trailing comma
}
# dont do this
foo = ('bar', 'baz', 'biz'
'lol', 'world')
# do this
foo = (
'bar',
'baz',
'biz',
)
@krimkus
Copy link

krimkus commented Mar 6, 2013

foo = {
'foo': 'bar',
'baz': 'biz', # always have a trailing comma
}

Agreed. Too bad trailing commas aren't valid JSON. It'd be nice if that changed so you could copy/paste between the two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment