我正在编写一个程序来读取5个文件中的文本行,并将这5个文件中的文本编译到相应的列表中。从文件中读取行
但是我有麻烦让程序实际读取文本列表很大,这是我到目前为止的代码:
from random import random
from dice import choose
b = open ('E:\Videos, TV etc\Python\ca2\beginning.txt', 'r'). readlines()
stripped_b = [item.strip() for item in b]
a = open ('E:\Videos, TV etc\Python\ca2\adjective.txt', 'r'). readlines()
stripped_a = [item.strip() for item in a]
i = open ('E:\Videos, TV etc\Python\ca2\inflate.txt', 'r'). readlines()
stripped_i = [item.strip() for item in i]
n = open ('E:\Videos, TV etc\Python\ca2\noun.txt', 'r'). readlines()
stripped_n = [item.strip() for item in n]
phrase = []
turn = 0
def business_phrase(x):
x = raw_input("\n\nInsert a number of business phrases to generate: ")
while turn <= x:
turn += 1
for item in stripped_b:
random_word = choose(item)
phrase.append(random_word)
for item in stripped_a:
random_word = choose(item)
phrase.append(random_word)
for item in stripped_i:
random_word = choose(item)
phrase.append(random_word)
for item in stripped_n:
random_word = choose(item)
phrase.append(random_word)
print random_list
business_phrase(X)
哪里开始,形容词,膨胀和名词是文本文件,骰子是一个包含选择函数的python文件。
我运行这个程序,试图生成一个短语,我得到了以下错误消息:
IOError: [Errno 22] invalid mode ('r') or filename 'E:\\Videos, Tv etc\\Python\\ca2\\x08eginning.txt'
我不知道为什么,因为他们是在同一个目录,因为它不会读取文本文件(事实上与包含该功能的程序在同一个目录中)。
没有人有我完全难倒任何想法。
你读过错误了吗?不,你真的*读过吗? –
是的,但我不知道它是什么意思,我是一个完整的初学者。 –
'\ x08'没有发出任何警告铃声? –