Python print statement “Syntax Error: invalid syntax”

PythonPython 3.xSyntaxSyntax Error

Python Problem Overview


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

Python Solutions


Solution 1 - Python

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

Solution 2 - Python

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

In Python 3 print "Hello world" gives invalid syntax error.

To display string content in Python3 have to use this ("Hello world") brackets.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohnnyFromBFView Question on Stackoverflow
Solution 1 - PythonmikerobiView Answer on Stackoverflow
Solution 2 - PythongnganapathView Answer on Stackoverflow