我是 Python 文件的新手,在删除输出控制台中的 '\n' 和单词None 时遇到了问题。这是我的代码:
def function(inputFile, wordFile):
input = open(inputFile, 'r')
words = open(wordFile, 'r')
wordList = []
for line in words:
wordList.append(line.split(','))
print(wordList)
words.close()
##call function
result = function("file1.txt","file2.txt")
print(result)
print()
我的 file2.txt/wordFile/words 看起来像这样:
你好世界
123,456
这是我得到的输出:
['你好', '世界\n']
['123', '456\n']
没有任何
我知道发生了很多事情,但是如何删除 '\n' 和None?
Helenr
相关分类