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?
Copyright Notice:Content Author:「andrean」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/10936164/python-coding-style