Python print statement "Syntax error: invalid syntax"

Why is Python giving me a syntax error in a 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","") 

Python version:

 Python 3.2.2 (default, Sep 4 2011, 09:07:29) [MSC v.1500 64 bit (AMD64)] on win 32 
+47
python syntax syntax-error
Sep 28 2018-11-21T00:
source share
2 answers

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

+105
Sep 28 2018-11-11T00:
source share

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

In Python 3, print "Hello world" displays an incorrect syntax error.

To display the contents of a string in Python3, you must use parentheses ("Hello world") .

+7
Apr 6 '13 at 7:37
source share



All Articles