【发布时间】:2013-04-02 21:44:11
【问题描述】:
我正在开发一个简单的 python 游戏,玩家试图猜测单词中包含的字母。问题是,当我打印一个单词时,它会在末尾打印 \n。
看来我需要使用 .strip 来删除它。但是,当我按照下面的代码使用它时,我收到一个属性错误,指出列表对象没有属性“strip”。
对不起,新手问题。
import random
with open('wordlist.txt') as wordList:
secretWord = random.sample(wordList.readlines(), 1).strip()
print (secretWord)
【问题讨论】:
-
看到你已经solved this problem,如果你在这里接受了对你有帮助的答案,那就太好了。
标签: python attributes