我试图使用python的tabulate函数将我的文件放入表中,但是它造成了不必要的空白:
G/T1593-1996 G/T1481-1996 G/T1481-1996 G/T1381-1996 G/T3103-1996 G/T1393-1996/C~(2)~(1)~(1)~(1)~(2)~(2)~(2)~(2)~(2)~(2)~(2)~(2)~(2)主要有3项较高的标准,6项标准.
我检查了我从那里得到的文件,没有空格。
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"))发布于 2015-02-06 20:40:15
看起来像是UTF-16的编码问题。当一个UTF-16文件被解释为UTF-8 (或其他几个文件)时,结果文本在普通字节之间有一个空字节(\x00),这看起来一切都被空格隔开了。
查看k's answer以获得处理它的好方法。
https://stackoverflow.com/questions/28362633
复制相似问题