Python 打印语句“语法错误:语法无效" [英] Python print statement “Syntax Error: invalid syntax”

查看:101
本文介绍了Python 打印语句“语法错误:语法无效"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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","")

Python 的版本是:

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

推荐答案

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

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

这篇关于Python 打印语句“语法错误:语法无效"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆