开发者

Python print statement “Syntax Error: invalid syntax” [duplicate]

开发者 https://www.devze.com 2023-04-09 15:43 出处:网络
This question already has answers here: 开发者_如何学CSyntax error on print with Python 3 [duplicate]
This question already has answers here: 开发者_如何学C Syntax error on print with Python 3 [duplicate] (3 answers) Closed 8 years ago.

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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号