Home  >  Q&A  >  body text

cli - Python 开发命令行程序如何省略python命令?

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

$ python3 test.py -h

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

$ test -h

alias别名不算哈。

PHP中文网PHP中文网2742 days ago285

reply all(3)I'll reply

  • 怪我咯

    怪我咯2017-04-17 18:02:58

    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

    reply
    0
  • PHPz

    PHPz2017-04-17 18:02:58

    py file first line:

    #! /usr/bin/python3
    chmod +x test.py
    ./test.py

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 18:02:58

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

    reply
    0
  • Cancelreply