Python打印语句“语法错误:无效语法”[重复]

时间:2021-01-21 22:43:47

This question already has an answer here:

这个问题已经有了答案:

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

为什么Python会在第9行中的简单print语句中给我一个语法错误?

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的版本是:

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

2 个解决方案

#1


111  

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

在Python 3中,print是一个函数,您需要像print(“hello world”)一样调用它。

#2


7  

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

使用print(“使用这个括号-示例文本”)

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

在Python 3中,打印“Hello world”会产生无效的语法错误。

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

要在Python3中显示字符串内容,必须使用这个(“Hello world”)方括号。

#1


111  

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

在Python 3中,print是一个函数,您需要像print(“hello world”)一样调用它。

#2


7  

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

使用print(“使用这个括号-示例文本”)

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

在Python 3中,打印“Hello world”会产生无效的语法错误。

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

要在Python3中显示字符串内容,必须使用这个(“Hello world”)方括号。