执行python代码 [英] executing python code
问题描述
前段时间我问过执行python程序或脚本。对于
windows,我被告知可以将.py扩展名添加到某些列表中,然后我可以输入mycode而不是
python mycode.py。很棒的建议,就像一个魅力。
我最近跳了船,并且已经运行Gentoo Linux大约两个月b $ b个月。是否有可能在Linux上获得相同的行为?我认为
会将#!/ usr / bin / env python行添加到我的
代码中,但我不知道这是什么应该这样做(它不起作用,我知道很多。)
我能得到一些建议吗?
谢谢,
Darren
Some time ago I asked about executing a python program or script. For
windows, I was informed that the .py extension could be added to some list
of executable extensions, and then I could just type "mycode" instead of
"python mycode.py". Great advice, worked like a charm.
I recently jumped ship, and have been running Gentoo Linux for about two
months. Is it possible to get the same behavior on Linux? I thought it
would have something to do with adding the #!/usr/bin/env python line to my
code, but I''m not sure what this is supposed to do (it didnt work, that
much I know.)
Could I get some advice?
Thanks,
Darren
推荐答案
Darren Dale< dd ** @ cornell.edu>写道:
Darren Dale <dd**@cornell.edu> writes:
前段时间我问过执行python程序或脚本。对于
窗口,我被告知可以将.py扩展名添加到某些可执行扩展名列表中,然后我只需键入mycode即可。而不是python mycode.py。很棒的建议,就像一个魅力。
我最近跳了船,并且已经运行Gentoo Linux大约两个月。是否有可能在Linux上获得相同的行为?我认为它会将#!/ usr / bin / env python行添加到我的代码中,但是我不确定它应该做什么(它没有用) ,我知道的很多。)
Some time ago I asked about executing a python program or script. For
windows, I was informed that the .py extension could be added to some list
of executable extensions, and then I could just type "mycode" instead of
"python mycode.py". Great advice, worked like a charm.
I recently jumped ship, and have been running Gentoo Linux for about two
months. Is it possible to get the same behavior on Linux? I thought it
would have something to do with adding the #!/usr/bin/env python line to my
code, but I''m not sure what this is supposed to do (it didnt work, that
much I know.)
怎么没有用?你做了什么,发生了什么?印刷了什么错误
?您是否使用chmod使脚本可执行?
脚本位于PATH中的目录中吗?是否在系统上安装了
?
-
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Michael Fuhr写道:
Michael Fuhr wrote:
Darren Dale< dd ** @ cornell.edu>写道:
Darren Dale <dd**@cornell.edu> writes:
前段时间我问过执行python程序或脚本。对于
窗口,我被告知.py扩展名可以添加到一些可执行扩展名列表中,然后我可以输入mycode而不是python mycode。 PY" ;.很棒的建议,就像一个魅力。
我最近跳了船,并且已经运行Gentoo Linux大约两个月。是否有可能在Linux上获得相同的行为?我认为它会将#!/ usr / bin / env python行添加到我的代码中,但我不确定它应该做什么(它没有用) ,
我知道的很多。)
Some time ago I asked about executing a python program or script. For
windows, I was informed that the .py extension could be added to some
list of executable extensions, and then I could just type "mycode"
instead of "python mycode.py". Great advice, worked like a charm.
I recently jumped ship, and have been running Gentoo Linux for about two
months. Is it possible to get the same behavior on Linux? I thought it
would have something to do with adding the #!/usr/bin/env python line to
my code, but I''m not sure what this is supposed to do (it didnt work,
that much I know.)
怎么没有用呢?你做了什么,发生了什么?印刷了什么错误?您是否使用chmod使脚本可执行?
脚本位于PATH中的目录中吗?是否在系统上安装了Python?
How didn''t it work? What did you do and what happened? What errors
were printed? Did you use chmod to make the script executable? Is
the script in a directory that''s in your PATH? Is Python installed
on the system?
是的,我做了chmod,脚本在当前目录中。
Yes, I did chmod, the script is in the current directory.
mycode.py
bash:mycode.py:命令未找到
我刚试过:
mycode.py
bash: mycode.py: command not found
I just tried:
这篇关于执行python代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!