推荐学习书目
› 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
JCZ2MkKb5S8ZX9pq
V2EX  ›  Python

怎么把 cmd 运行目录传入 Python

  •  
  •   JCZ2MkKb5S8ZX9pq · Dec 24, 2019 · 3390 views
    This topic created in 2526 days ago, the information mentioned may be changed or developed.
    • python 文件位于 c:\python\test.py
    • cmd 运行路径是 c:\run\
    • 运行 c:\run> python c:\python\test.py
    • sys.argv 得到的是 c:\python\test.py
    • 在 python 内怎么获取到 c:\run ?
    7 replies  •  2019-12-25 09:45:50 +08:00
    gwy15
    gwy15
    Dec 24, 2019❤️1
    1
    from pathlib import Path
    Path('.').absolute()
    JCZ2MkKb5S8ZX9pq
    JCZ2MkKb5S8ZX9pq
    OP
    Dec 24, 2019
    2
    @gwy15 感谢,有效,第一次看到这个 module。
    xiaoming1992
    xiaoming1992
    Dec 24, 2019
    3
    我是直接在 python 里执行 os.system("cd ...... & .......")
    lxk11153
    lxk11153
    Dec 24, 2019
    4
    环境变量?
    ysc3839
    ysc3839
    Dec 24, 2019 via Android❤️2
    5
    这是当前工作目录,可以用 os.getcwd()
    JCZ2MkKb5S8ZX9pq
    JCZ2MkKb5S8ZX9pq
    OP
    Dec 24, 2019
    6
    @ysc3839 对哦。这个更加简洁一点。
    wuwukai007
    wuwukai007
    Dec 25, 2019
    7
    os.child(xxx)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3052 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 00:46 · PVG 08:46 · LAX 16:46 · JFK 19:46
    ♥ Do have faith in what you're doing.