Python打印语句 “Syntax Error: invalid syntax”

标签 python python-3.x syntax syntax-error

为什么 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","")

Python的版本是:

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

最佳答案

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

关于Python打印语句 “Syntax Error: invalid syntax”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7584489/

相关文章:

c++ - Python:有一个用户定义的函数作为输入,同时保持源代码不可访问?

python - 当列表在字典中时查找列表的元素?

django - 如何从 django 中的 python 文件导入一个类?

objective-c - 在 Objective-C 中否定 BOOL 的最短方法是什么?

function - 我真的对 Haskell 中的函数声明感到困惑

python - TKinter:如何创建直方图?

python - 是否可以在 Python 中创建具有未知属性的类?

python - 如何在 Python 3.7 中向 multiprocessing.connection.Client(..) 添加超时?

php - 日期为 'categories' 的 SQL JOIN

python - 如何使用 Python 从 Facebook 评论插件获取文本?