推荐学习书目
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 · 3206 views
    This topic created in 2399 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
        1
    gwy15  
       Dec 24, 2019   ❤️ 1
    from pathlib import Path
    Path('.').absolute()
    JCZ2MkKb5S8ZX9pq
        2
    JCZ2MkKb5S8ZX9pq  
    OP
       Dec 24, 2019
    @gwy15 感谢,有效,第一次看到这个 module。
    xiaoming1992
        3
    xiaoming1992  
       Dec 24, 2019
    我是直接在 python 里执行 os.system("cd ...... & .......")
    lxk11153
        4
    lxk11153  
       Dec 24, 2019
    环境变量?
    ysc3839
        5
    ysc3839  
       Dec 24, 2019 via Android   ❤️ 2
    这是当前工作目录,可以用 os.getcwd()
    JCZ2MkKb5S8ZX9pq
        6
    JCZ2MkKb5S8ZX9pq  
    OP
       Dec 24, 2019
    @ysc3839 对哦。这个更加简洁一点。
    wuwukai007
        7
    wuwukai007  
       Dec 25, 2019
    os.child(xxx)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   899 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 19:54 · PVG 03:54 · LAX 12:54 · JFK 15:54
    ♥ Do have faith in what you're doing.