![](/img/trans.png)
[英]How to select a column name and use it as input for a variable name in Python?
[英]how to use input variable for file name in python
我正在尝试with open(fileName,'rb') as csvfile:
来做到这一点。 如果我硬编码fileName的名称,则可以使用,但是如果我使用fileName = input("Enter file name: ")
则会收到错误消息
...
fileName = input("Enter file name: ")
File "<string>", line 1, in <module>
NameError: name 'page1' is not defined
其中page1.csv
是目标文件,以及在要求输入时输入的内容。 我怎样才能解决这个问题?
您正在使用Python2。您需要使用raw_input
而不是input
。
raw_input
将为您提供预期的字符串值。 input
尝试将其作为Python表达式运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.