我有一个字典文本文件,我想给每个单词添加一个字符串,比如"http://" + word + ".com"
我试过这个:
f = open('esp.txt', 'r')
urls = open('urls.txt', 'w')
while True:
nline = 1
contentCOM = 'http://www.' + f.readlines(nline) + '.com'
contentCOM.write(urls)
nline = nline + 1
但它给了我以下错误:TypeError: Must be str, not list
如果你所有的“话”都在一行又一行esp.txt文件,然后可以这样迭代:
看起来您使用的是
readlines()
与单数readline()
https://docs.python.org/3.7/tutorial/inputoutput.html#methods-of-file-objects
提示是,如果您查看错误和行号,您会注意到这里得到的是一个列表而不是一个字符串:
最好检查Python文档并查看
readlines()
的输出,看看输出是什么。然后,您将把列表输出放在一起,说明是您的错误,并将查找一个新函数。你知道吗相关问题 更多 >
编程相关推荐