Command-line input causes SyntaxError

Posted by coson on Stack Overflow See other posts from Stack Overflow or by coson
Published on 2010-04-07T00:43:37Z Indexed on 2010/04/07 12:33 UTC
Read the original article Hit count: 308

Filed under:
|
|
|

Good Day,

I have a simple Python question that I'm having brain freeze on. This code snippet works. But when I substitue "258 494-3929" with phoneNumber, I get the following error below:

# 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!"  

#######################################################

 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>  

By the way, I did import re and tried using rstrip in case of the \n

What else could I be missing? Thanks in advance.

© Stack Overflow or respective owner

Related posts about python

Related posts about beginner