在python中,无论如何输入不带引号的字符串?

时间:2016-05-24 03:58:32

标签: python python-2.7 input

我希望用户输入表格的名称,table = str(input("table: "))有效,但每次放'name'而不仅仅是name都有点烦人,有没有解决这个问题?

1 个答案:

答案 0 :(得分:2)

使用raw_input

table = raw_input("table: ")
  

输入([提示])

Equivalent to eval(raw_input(prompt))

This function does not catch user errors. If the input is not syntactically valid, a SyntaxError will be raised. Other exceptions may be raised if there is an error during evaluation.

If the readline module was loaded, then input() will use it to provide elaborate line editing and history features.

Consider using the raw_input() function for general input from users.