I've been reading various python coding style guides, some answers on SO, etc. but none of them mentions some maybe not that important questions, but I would like to know if there is a preferred way for doing this:
In case I have a dictionary, which style would be better to use:
dict_name = {'test': 'somevalue',
'test2': 'other'}
or
dict_name = {
'longer_key': 'somevalue',
'longer_key2': 'other'
}
or
dict_name = {
'test': 'somevalue',
'test2': 'other'
}
or
dict_name = {
'test': 'somevalue',
'test2': 'other'
}
or something else?
Also for when calling methods:
function_name(longer_arg1, longer_arg2, longer_arg3,
longer_arg4)
or
function_name(longer_arg1, longer_arg2, longer_arg3,
longer_arg4)
or
function_name(
longer_arg1,
longer_arg2,
longer_arg3,
longer_arg4
)
or
function_name(
longer_arg1,
longer_arg2,
longer_arg3,
longer_arg4
)
or something else?
when a longer logging line is used, let's say:
loggername.info('this is an awfully long line which must be separated'
'into two lines, am I doing it right? {0}'.format('nope..'))
or even consider this:
loggername.info('this is an {0} {1} line which must be separated'
'into {2} lines, am I doing it right? {0}'.format(
'awfully', 'short', 'three', 'nope..')
)
Now this last is somewhat related to the function calling style too, we have many arguments, a long string, how would be the best to separate these kind of lines?
You can't go wrong with looking at the PEP 8 - The Style Guide for Python Code for guidance on how to write readable Python code. Highly recommended.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With