Python print语句“语法错误:无效语法”

2024-04-20 05:26:45 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

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

Tags: thenameinputrawissyshash语句
2条回答

使用print("use this bracket -sample text")

在Python 3中,print "Hello world"给出无效的语法错误。

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

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

相关问题 更多 >