文本换行格式错误修复

时间:2016-05-02 21:45:09

标签: python-2.7 textwrapping

我在textwrap模块中工作,要求输出的文本看起来像see picture of expected output formatting

但是,我的输出如下: see my output

这是我用于文本换行的代码:

wrap = textwrap.TextWrapper(initial_indent = ' '*4, subsequent_indent = ' '*4)
if name not in bus_name:
    print 'This business is not found'
else:
    count = 0
    for id in bus_name[name]:
        if id not in bus_review:
            print 'No reviews for this business are found'
        else:
            for rev in bus_review[id]:
                print 'Review %d' %(count+1)
                string = textwrap.fill(rev)
                string = string.replace('  ', '$')
                string = wrap.fill(string)
                string = string.replace('$', '\n'+' '*4)
                print '%s' %string
                print 
                count += 1

0 个答案:

没有答案
相关问题