大家帮我看看这个功能该怎么实现 - V2EX
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
craiiz

大家帮我看看这个功能该怎么实现

  •  
  •   craiiz Apr 6, 2020 3168 views
    This topic created in 2229 days ago, the information mentioned may be changed or developed.

    tuxiang

    如上图所示

    我想实现:双击 command.command 文件自动运行 manage.py,需要在 command 文件里怎么写?

    当前情况:在 command 文件里只写了 python manage.py

    分析:需要 command 文件运行的时候能够获取当前正在运行的 command 文件的路径;类似于 python 的 sys.path[0] 或者 os.path.basename[file]的效果。 补充之后的 command 文件内容应该类似于:

    """

    cd 当前 command 文件路径;
    python manage.py

    """

    但是目前 google 许久,没有找到类似的终端命令 求大神相助。。。。。。

    10 replies    2020-05-15 11:07:03 +08:00
    Trim21
        1
    Trim21  
       Apr 6, 2020
    command 应该是由 shell 来解释的吧?应该看看 zsh 的语法
    Trim21
        2
    Trim21  
       Apr 6, 2020
    搜了下,zsh 里面大概是这样
    python "${0:a:h}/main.py"
    craiiz
        3
    craiiz  
    OP
       Apr 6, 2020
    感谢 @Trim21
    已解决,需要在前面加上一句:cd $(dirname $BASH_SOURCE)
    also24
        4
    also24  
       Apr 6, 2020 via Android
    没太理解楼主的目的,直接使用:

    python ./manage.py

    会有什么问题出现嘛?
    craiiz
        5
    craiiz  
    OP
       Apr 6, 2020
    微博的图那么快就挂了???
    craiiz
        6
    craiiz  
    OP
       Apr 6, 2020
    @also24 没想到微博的图那么快就挂了。但这样会不能运行,会提示:
    python: can't open file './manage.py': [Errno 2] No such file or directory
    logout
    Saving session...
    ...copying shared history...
    ...saving history...truncating history files...
    ...completed.
    craiiz
        7
    craiiz  
    OP
       Apr 6, 2020
    微博图挂了,为保证主题质量,之后有人遇到同样问题还可解决。现重述问题:


    场景:command 。command 和 manage 。py 在同一个文件夹

    我想实现:双击 command 。command 文件自动运行 manage 。py,需要在 command 文件里怎么写?

    当前情况:在 command 文件里只写了 python manage 。py 。

    分析:需要 command 文件运行的时候能够获取当前正在运行的 command 文件的路径;类似于 python 的 sys 。path[0] 或者 os 。path 。basename[file]的效果。 补充之后的 command 文件内容应该类似于:

    """

    cd 当前 command 文件路径;
    python manage 。py

    """

    但是目前 google 许久,没有找到类似的终端命令 求大神相助。。。。。。
    Trim21
        8
    Trim21  
       Apr 6, 2020
    @also24 #4 大概因为 pwd 不是这个文件夹,所以找不到这个 manage.py
    oott123
        9
    oott123  
       Apr 6, 2020 via Android
    先写一个 bash 内容是 cd xx; python manager.py 再在 command 里指向这个 bash

    当然你可以查查 command 有没有改 working directory 的功能,应该也有
    craiiz
        10
    craiiz  
    OP
       May 15, 2020
    已解决,谢谢各位大神
    About     Help     Advertise     Blog     API     FAQ     Solana     1029 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 73ms UTC 22:33 PVG 06:33 LAX 15:33 JFK 18:33
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86