how to make a python file run without py extension

◇◆丶佛笑我妖孽 提交于 2019-12-03 13:07:59

Unix-like OS solution: the first line of the file should be #!/usr/bin/python (or wherever the python interpreter is) and chmod u+x the script. Run it with ./some_file parameters.

If you want to launch it with some_file parameters simply make a link to the script in a directory which is already included into your PATH: sudo ln -s some_file /usr/bin.

So, here's the full procedure:

blackbear@blackbear-laptop:~$ cat > hw
#!/usr/bin/python

print "Hello World!"

blackbear@blackbear-laptop:~$ chmod u+x hw
blackbear@blackbear-laptop:~$ sudo ln -s hw /usr/bin
blackbear@blackbear-laptop:~$ hw
Hello World!
blackbear@blackbear-laptop:~$ 
TangZ

make a symbolic link

ln -s some_file.py some_file

now you can type your cmd like this:

some_file Steve Jobs

you can run the same program in python shell by using execfile('path').

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!