我正在使用.rstrip从导入的文本文件中的单词中删除\ n,但是它作为属性错误出现了?
AttributeError:“列表”对象没有属性“ rstrip”
import random
import os
import time
text_file = open ("ten_words.txt", "r")
lines = text_file.readlines()
missing = random.choice(lines)
random.shuffle(lines)
print ("First Grid")
print ("\n", lines.rstrip[0],"|", lines.rstrip[1], "|", lines.rstrip[2])
print ("\n", lines.rstrip[3],"|", lines.rstrip[4], "|", lines.rstrip[5])
print ("\n", lines.rstrip[6],"|", lines.rstrip[7], "|", lines.rstrip[8])
您在这里订购有误,您要做的是:
lines[0].rstrip('\n')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句