清洁管理各种打印条件?

时间:2019-06-27 23:19:36

标签: python

我在这里有这段代码,可以打印出我现在可用的数据,这些数据现在imo看起来很差而且杂乱无章:

has_printed = 0
output = ''

is_banner_printed = 0
if time.time() > next_print_time:
    output = output + (' ' + datetime.now().strftime("%I:%M:%S %p") + ' ---------------------------------------------------------------------------------c')
    is_banner_printed = 1

if is_banner_printed or not(len(self.post_list)):
    print(output)

output = ''
for i, post in enumerate(self.post_list):

    post.update()

    output = output + ('   Age: ' + datetime.fromtimestamp(self.utils.get_submission_age(post.created_utc)).strftime("%M:%S") +
                       ' | URL: http://url.com/' + post.id +
                       ' | Score: ' + str(post.score).ljust(6, ' ') + ... )
    if i == 0:
        output = '\n' + output
    output = output + '\n'

if output is not '' and time.time() > next_print_time and is_banner_printed:
    print(output)
    has_printed = 1
    next_print_time = time.time() + self.PRINT_RATE

if has_printed:
    print(' ---------------------------------------------------------------------------------------------c\n\n\n')
elif is_banner_printed and output is '':
    print('')
    next_print_time = time.time() + self.PRINT_RATE

我想知道是否有可能清理此混乱以使实际代码可读?

0 个答案:

没有答案