首先,readlines返回一个列表,因此您需要应用rstrip到它的元素,而不是应用到它,并且,您'/n'在代码中进行条带化(应该是'\n'),最后,您没有使用path变量 in open(不使用它不会导致一个错误,但你可能应该使用它,因为你定义了它):path =('a.txt', 'r')with open(*path) as f: # use `with` to automatically close the file after reading read = [l.rstrip('\n') for l in f.readlines()]另请注意,您可以只使用l.rstrip()(不需要'\n') 来删除空格。