如何使没有py扩展名的python文件运行 [英] how to make a python file run without py extension
本文介绍了如何使没有py扩展名的python文件运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个小的python脚本,该脚本从命令行参数获取输入并完成了一些操作 使用所获取的输入进行操作并显示结果
I had a small python script that takes input from the command line arguments and done some operations using the inputs taken and display the result
下面是工作示例代码
some_file.py
import sys
arguments = sys.argv
first_name = sys.argv[1]
second_name = sys.argv[2]
print "Hello {0} {1} !!!!".format(first_name,second_name)
现在我以
python some_file.py Steve jobs
结果:
Hello Steve Jobs !!!!
现在我想要的是什么,我不想在文件名和python文件名的扩展名前使用python命令,也就是说,我想将文件作为以下命令工具运行
Now what all i want is, i don't want to use python command before file name and extension of python file name, that is i want to run the file as a command tool as below
some_file Steve Jobs
那么要如何运行上述python文件呢?
so what to do in order to run the python file as above ?
推荐答案
建立符号链接
ln -s some_file.py some_file
现在您可以像这样输入您的cmd:
now you can type your cmd like this:
some_file Steve Jobs
这篇关于如何使没有py扩展名的python文件运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文