简体   繁体   English

为什么我不能在Python Shell中运行代码?

[英]Why can't I run my codes in Python Shell?

def thisisfun(x,y,z):
    x=2
    y=3
    z=4 
    print('AHHHHA')
thisisfun(333,"annoy",2142125)

If it is with the last line, then after I clicked on Execute Current File it actually prints AHHHHA But when I attempted to have thisisfun(333,"annoy",2142125) in Python Shell (without the last line), it says name 'thisisfun' is not defined I dont know what happened to my WingIDE...:( Help.. 如果在最后一行,那么在我单击“ Execute Current File它实际上会打印AHHHHA但是,当我尝试在Python Shell(无最后一行)中使用thisisfun(333,“ annoy”,2142125)时,其name 'thisisfun' is not defined我不知道我的WingIDE ... :(帮助..

You need an empty line after your function definition or the parser gets confused: 您需要在函数定义后留空行,否则解析器会感到困惑:

def thisisfun(x,y,z):
    x=2
    y=3
    z=4 
    print('AHHHHA')

thisisfun(333,"annoy",2142125)

This makes it clear that the function call is not part of the function itself. 这清楚表明函数调用不是函数本身的一部分。

Execute Current File runs that file outside of the debugger until it terminates. 执行当前文件在调试器外部运行该文件,直到终止。 This does not happen in the context of the Python Shell's runtime environment, but in a separate process. 这并不在Python壳牌的运行时环境的背景下发生的,而是在一个单独的进程。 If you want to work with this in the Python Shell then use Evaluate File in Python Shell in the Source menu. 如果要在Python Shell中使用此功能,请在“源”菜单中使用“ Python Shell中的评估文件”。 After that, thisisfun is defined in the Python Shell's environment until you restart it from its Options menu. 之后,在Python Shell的环境中定义thisisfun,直到您从其“选项”菜单重新启动它为止。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尽管我的文本编辑器可以运行,但我无法在 Windows Power Shell 中运行我的 python 代码 - I can't run my python codes in Windows Power Shell despite my text editor can run 为什么我的 Python 代码不能将图表绘制到指定目录? - Why can't my Python codes plot diagram to the designated directory? 为什么我不能从另一个运行我的python文件? - Why can't I run my python file from another? 为什么我的Python程序无法正常运行? 它可以运行,但没有得到我想要的结果 - Why my Python program can't run correctly? It can run but don't get the result I want to 为什么我可以在python 3.6 shell中访问gdal但不能在django shell中访问 - Why can I access gdal in my python 3.6 shell but not my django shell 我从官方网站安装了Python 3.6.0。 但是当我运行python时-我的bash shell上的版本是2.7.1。 我也不知道为什么 - I installed Python 3.6.0 from the official website. But when i run python — version on my bash shell .it say 2.7.1. And i don't know why 为什么我不能从命令提示符运行 python 代码? - Why can't I run python code from my command prompt? 为什么我不能在Datastax Enterprise中运行我的spark python脚本? - Why can't I run my spark python script with Datastax Enterprise? 为什么我不能通过我的 cmd 成功运行这个 python 文件? [等候接听] - Why can't I successfully run this python file through my cmd? [on hold] 为什么我不能通过我的 python 生成器运行 linspace()? (初学者) - Why can't I run linspace() through my python generator? (Beginner)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM