Python print statement “Syntax Error: invalid syntax”

JohnnyFromBF picture JohnnyFromBF · Sep 28, 2011 · Viewed 208.5k times · Source

Why is Python giving me a syntax error at the simple print statement on line 9?

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","")

The version of Python is:

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

Answer

mikerobi picture mikerobi · Sep 28, 2011

In Python 3, print is a function, you need to call it like print("hello world").