【发布时间】:2013-08-28 13:36:41
【问题描述】:
我有一个文件名列表 例如。文件名=['blacklisted.txt', 'abc.txt', 'asfafa.txt', 'heythere.txt']
我想让用户手动选择要显示的文件名,例如,
*
print "Please key in the first log file you would like to use: "
choice1=raw_input()
print"Please key in the second log file you would like to use: "
choice2=raw_input()
filename1=filenames[choice1]
filename2=filenames[choice2]
print filename1
print filename2
*
但是,我得到了错误: 文件名1=文件名[选择1] TypeError: 列表索引必须是整数,而不是 str。
有什么建议吗?谢谢!
【问题讨论】:
-
choice1=int(raw_input()),使用int()。