且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用for循环从Python的外部文件中打印列表的每个项目

更新时间:2023-11-28 16:46:22

拆分换行符并以您的格式输出:

Splitting on newlines and outputting in your format:

from ast import literal_eval

file_contents = file.readlines() #read the file as lines
for line in file_contents:
    l = literal_eval(line) #convert the string to a list
    print(''.join([v.ljust(10, ' ') for v in l])) #left justify and print