cli - Python 开发命令行程序如何省略python命令?
PHP中文网
PHP中文网 2017-04-17 18:00:58
0
3
283

比如我写好了一个test.py脚本,通常都要这样调用:

$ python3 test.py -h

我想问大家如何实现下面的这样:

$ test -h

alias别名不算哈。

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
刘奇

Create a file such as /usr/sbin/test

Test code

#! /usr/bin/python3

print('my test')

Give the file executable permission

chmod +x /usr/sbin/test

In this way, you can directly access the test command in any directory in the console
If your directory is not in $PATH, add it yourself

PHPzhong

py file first line:

#! /usr/bin/python3
chmod +x test.py
./test.py
大家讲道理

You can add alias in .bash_profile or
establish a soft connection in /usr/bin/

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!