使用 PyScripter 定义函数的 Python 中的无效语法错误 [英] Invalid syntax error in python defining a function with PyScripter

查看:85
本文介绍了使用 PyScripter 定义函数的 Python 中的无效语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 PyScripter IDE 中编写此代码:

I am trying to write this in PyScripter IDE:

def f(a):
    print a

它说:语法错误,无效语法.但是,如果我在 Python Shell 中尝试相同的代码就可以了,我可以看到结果

and it says: Syntax Error, Invalid syntax. However if I try the same code in the Python Shell it is OK and I can see the result

推荐答案

Pyscripter 默认使用最新版本的 python available 所以你可能在 pyscripter 上使用 python 3 where print 是一个函数,所以请尝试:

Pyscripter by default uses the latest version of python available So You are probably using python 3 on pyscripter where print is a function so instead try:

def f(a):
    print(a)

并将 pyscripter 设置为使用 python 2 将此添加到您的 pyscripter 快捷方式中,将 target 字段编辑为:

And to set pyscripter to use python 2 add this to your pyscripter shortcut edit the target field to look like:

"path_2_PyScripter.exe" --PYTHON27

这篇关于使用 PyScripter 定义函数的 Python 中的无效语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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