我试图使用python的tablate函数将我的文件放入一个表中,但是这会造成不必要的间隙:[ ' E w a n ' , ' S m i t h ' , 1 0 , 2 , 5 ] [ ' J o h n ' , ' S m i t s ' , 2 , 6 , 7 ] [ ' A m y ' , ' G i n ' , 2 , 3 , 6 ] [ ' M i c h e a l ' , ' J o n e s ' , 2 , 3 , 4 ].
我检查了我从中得到的文件,没有空格。在from tabulate import tabulate
scores=[]
studentscores=[]
class1=[]
class2=[]
class3=[]
classes=input("Hello, which class do you wish to open:")
if classes=='mathA':
with open('mathA.txt')as file:
for line in file:
scores.append(line.strip())
classes=["b","C","A"]
classes.sort()
print (tabulate(scores, headers=["Name","scores"],
tablefmt="plain", numalign="right"))