我想读的文本文件,并从所有行提取每一个字,使字符串列表如下图所示:从文件转换为文本字符串列表在python
['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 'breaks', 'east',
'envious', 'fair', 'grief', 'is', 'kill', 'light', 'moon', 'pale', 'sick',
'soft', 'sun', 'the', 'through', 'what', 'window', 'with', 'yonder']
我写了这个代码:
fname = raw_input("Enter file name: ")
fh = open(fname)
lst = list()
for line in fh:
lst.append(line.split())
print lst
print lst.sort()
当我对它进行排序时,它最终只给出了一个无。 我得到这个意外的结果!
[['But', 'soft', 'what', 'light', 'through', 'yonder', 'window', 'breaks'],
['It', 'is', 'the', 'east', 'and', 'Juliet', 'is', 'the', 'sun'], ['Arise',
'fair', 'sun', 'and', 'kill', 'the', 'envious', 'moon'], ['Who', 'is',
'already', 'sick', 'and', 'pale', 'with', 'grief']]
None
我完全失去了。我做错了什么?
文本文件的格式是什么? – pzp
它是一种平面的文字file.But柔和什么光那边窗子里 那是东方朱丽叶就是太阳 起来美丽的太阳,杀死羡慕月亮 谁已经面色惨白悲伤 –