Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3-对齐和间距_Python_Python 3.x - Fatal编程技术网

Python 3-对齐和间距

Python 3-对齐和间距,python,python-3.x,Python,Python 3.x,我正在尝试使用另一个文本文件中的信息创建一个新的文本文件。 i、 e 我希望它看起来像: name number country (左对齐和特定宽度) 我试图将其向左对齐,并在列之间创建特定的间距 我有此问题,无法找到解决方案,最接近的语法如下: lines = old_file.readlines() print ("{0:<25} {1:<6} {2:<35}".f

我正在尝试使用另一个文本文件中的信息创建一个新的文本文件。 i、 e

我希望它看起来像:

name                         number                               country
(左对齐和特定宽度)

我试图将其向左对齐,并在列之间创建特定的间距

我有此问题,无法找到解决方案,最接近的语法如下:

lines = old_file.readlines()
print ("{0:<25} {1:<6} {2:<35}".format(*lines)
lines=old_file.readlines()

打印(“{0:您忘记拆分行并在每行上循环:

lines = old_file.readlines()
for l in lines:
    print('{0:<25} {1:<6} {2:<35}'.format(*l.split(',')))
lines = old_file.readlines()
for l in lines:
    print('{0:<25} {1:<6} {2:<35}'.format(*l.split(',')))
john doe                   88     uk                                
mike green                 212    usa