La entrada de la línea de comandos provoca SyntaxError
Tengo una pregunta simple de Python que me está congelando el cerebro. Este fragmento de código funciona. Pero cuando sustituyo "258 494-3929" con phoneNumber, aparece el siguiente error a continuación:
# Compare phone number
phone_pattern = '^\d{3} ?\d{3}-\d{4} 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>
Por cierto, lo hiceimport re
e intenté usarrstrip
en caso de\n
¿Qué más podría faltar?
# 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>
Por cierto, lo hiceimport re
e intenté usarrstrip
en caso de\n
¿Qué más podría faltar?