2011-09-28 17 views
47

¿Por qué Python me da un error de sintaxis en la simple declaración print en la línea 9?Python print statement "Error de sintaxis: sintaxis no válida"

import hashlib, sys 
m = hashlib.md5() 
hash = "" 
hash_file = raw_input("What is the file name in which the hash resides? ") 
wordlist = raw_input("What is your wordlist? (Enter the file name) ") 
try: 
    hashdocument = open(hash_file,"r") 
except IOError: 
    print "Invalid file." # Syntax error: invalid syntax 
    raw_input() 
    sys.exit() 
else: 
    hash = hashdocument.readline() 
    hash = hash.replace("\n","") 

La versión de Python es:

Python 3.2.2 (default, Sep 4 2011, 09:07:29) [MSC v.1500 64 bit (AMD64)] on win 
32 

Respuesta

107

En Python 3, la impresión es una función, es necesario llamar así print("hello world").

7

Uso print("use this bracket -sample text")

En Python 3 print "Hello world" da error de sintaxis no válida.

Para mostrar el contenido de cadena en Python3 tiene que usar este ("Hello world") paréntesis.