用python编写一个hangman程序,我在传递一个包含多字串和单字串的文件时遇到了一个问题。
文件:
你好棕狐
狗
猫
水
跳
#initialize list
wordList = []
# get and open file
getFile = raw_input("Enter file name: ")
filename = open(getFile, "r")
def readWords(filename):
for line in filename:
# split any multi word line
line.split()
# add line to wordList
wordList.append(line)
然而 wordList 的输出仍然显示:
wordList = ['hello brown fox\n', 'dog\n', 'cat\n', 'water\n', 'jump\n']
我正在尝试使“hello brown fox”显示为 3 个单独的字符串。