相关疑难解决方法(0)

命令行输入会导致SyntaxError

我有一个简单的Python问题,我正在大脑冻结.此代码段有效.但是当我用phoneNumber替换"258 494-3929"时,我收到以下错误:

# Compare phone number  
 phone_pattern = '^\d{3} ?\d{3}-\d{4}$'

 # phoneNumber = str(input("Please enter a phone number: "))

 if re.search(phone_pattern, "258 494-3929"):  
        print "Pattern matches"  
  else:  
        print "Pattern doesn't match!"  
Run Code Online (Sandbox Code Playgroud)
 Pattern does not match  
 Please enter a phone number: 258 494-3929  
 Traceback (most recent call last):  
    File "pattern_match.py", line 16, in <module>  
      phoneNumber = str(input("Please enter a phone number: "))  
    File "<string>", line 1  
      258 494-3929  
          ^
  SyntaxError: invalid syntax

   C:\Users\Developer\Documents\PythonDemo>  
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我做过import re并尝试过使用rstrip的情况\n

我还能错过什么?

python command-line input python-2.x

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

command-line ×1

input ×1

python ×1

python-2.x ×1