我正在研究一个简单的python游戏,玩家试图猜测包含在单词中的字母。问题在于,当我打印一个单词时,它会在最后打印\ n。python属性错误?
它看起来像我需要使用.strip将其删除。但是,如以下代码所示,当我使用它时,出现属性错误,表明列表对象没有属性“strip”。
对不起,这个新手问题。
import random
with open('wordlist.txt') as wordList:
secretWord = random.sample(wordList.readlines(), 1).strip()
print (secretWord)
看到,因为你已经[解决了这个问题](http://stackoverflow.com/questions/15775920/letter-guessing-game-in-python),如果你接受了这个帮助你的答案,那将会很好。 –