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

请教一个问题关于 os 模块中的 getcwd

  •  
  •   tin · Jul 21, 2014 · 3710 views
    This topic created in 4323 days ago, the information mentioned may be changed or developed.
    import os
    os.getcwd()就可以看到当前路径,
    但我在看 os.py 这个文件时,没有找到关于 getcwd这个函数请问是为什么?谢谢。
    6 replies    2014-07-22 02:19:58 +08:00
    timonwong
        1
    timonwong  
       Jul 21, 2014
    __all__.extend(_get_exports_list(blahblahblah))

    blahblahblah 是 builtin 的模块, 对应不同平台,比如 windows, posix

    源代码看 Modules/posixmodule.c
    tin
        2
    tin  
    OP
       Jul 21, 2014
    谢谢,但没看明白。。。。
    timonwong
        3
    timonwong  
       Jul 21, 2014
    @tin

    那就简单的说吧,getcwd这些不是由python实现的,是c实现的
    tin
        4
    tin  
    OP
       Jul 21, 2014
    @timonwong 明白了。谢谢。是说 getcwd 不是 os 模块里的函数是吧?而是 builtin 里的?那为什么要用 os.getcwd 调用呢?不好意思。初学者,比较小白。问题可能有点弱。请见谅
    timonwong
        5
    timonwong  
       Jul 21, 2014
    @tin
    因为那是平台相关的,Python给这些函数导出了不同的模块名

    sys.builtin_module_names # 所有builtin的模块,你可以试试

    比如在windows上,这个名字是 nt, nt.getcwd
    linux上,这个名字是 posix, posix.getcwd

    把这些导出到 os,至少在接口方面,是平台无关的。
    tin
        6
    tin  
    OP
       Jul 22, 2014
    非常感谢,有点明白了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   942 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 20:16 · PVG 04:16 · LAX 13:16 · JFK 16:16
    ♥ Do have faith in what you're doing.