python - How to indent this line for pep8 compatibility -
how can indent line inside loop compatible pep8?
for ii in range(len(file_time)): file_time[ii] = datetime.strptime(str(file_date[ii]) + " " + str(file_time[ii]),'%y/%m/%d %h:%m:%s.%f').replace(microsecond=0)
i've tried 2 of options pep8 documentation offers:
# aligned opening delimiter. foo = long_function_name(var_one, var_two, var_three, var_four) # hanging indents should add level. foo = long_function_name( var_one, var_two, var_three, var_four)
but still same error:
script.py:36:9:e122 continuation line missing indentation or outdented
the hanging indent should work fine:
for ii in range(len(file_time)): file_time[ii] = datetime.strptime( str(file_date[ii]) + " " + str(file_time[ii]), '%y/%m/%d %h:%m:%s.%f').replace(microsecond=0)
you can improve on avoiding using str()
conversions (you have strings, surely), , using zip()
, list comprehension:
file_time = [ datetime.strptime('{} {}'.format(fd, ft) '%y/%m/%d %h:%m:%s.%f').replace(microsecond=0) fd, ft in zip(file_date, file_time)]
you can extract conversion function too:
def as_dt(datestr, timestr, fmt='%y/%m/%d %h:%m:%s.%f'): dt = datetime.strptime('{} {}'.format(fd, ft), fmt) return dt.replace(microsecond=0) file_time = [as_dt(fd, ft) fd, ft in zip(file_date, file_time)]
Comments
Post a Comment