python-TypeError:无效文件:尝试使文件成为列表时
当我运行此命令时:python-TypeError:无效文件:尝试使文件成为列表时,python,list,file,Python,List,File,当我运行此命令时: with open(cs, 'r') as f : Candidates = [line.strip() for line in f] 我得到一个错误: TypeError: invalid file: ['bob', 'john', 'nancy', 'johnnie', 'sam'] 这似乎做了正确的事情,因为它正在打开文件“cs”,并将值放入该字符串中。我看到另一个踏板上写着,去掉“r”可以修复它,但它不起作用 提前谢谢你的帮助 cs的值是['bob
with open(cs, 'r') as f :
Candidates = [line.strip() for line in f]
我得到一个错误:
TypeError: invalid file: ['bob', 'john', 'nancy', 'johnnie', 'sam']
这似乎做了正确的事情,因为它正在打开文件“cs”,并将值放入该字符串中。我看到另一个踏板上写着,去掉“r”可以修复它,但它不起作用
提前谢谢你的帮助
cs
的值是['bob'、'john'、'nancy'、'johnnie'、'sam']
'cs'
(用引号括起来)或str类型的变量
cs
的值是多少?确保cs=“/path/to/file”
。