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

Python 把文件名和文件内一个类弄成同名, 又使用了 multiprocess 会造成 import 不到文件的问题?

  •  1
     
  •   kamushin · Apr 25, 2016 · 4155 views
    This topic created in 3723 days ago, the information mentioned may be changed or developed.
    Supplement 1  ·  Apr 25, 2016
    问题找到了, 用 trace 找到一处循环 import
    9 replies    2016-04-26 00:14:48 +08:00
    zhicheng
        1
    zhicheng  
       Apr 25, 2016 via Android
    import 不到会 raise 一个 error 。你的情况很可能只是名字被覆盖了。
    fds
        2
    fds  
       Apr 25, 2016
    纯吐槽: python 的 import 规则太奇怪,特别是相对路径基本没法用,还是 node.js 的比较直观
    kamushin
        3
    kamushin  
    OP
       Apr 25, 2016
    @zhicheng 确实 raise 了 error. 我使用了 from A import * . 结果 A 中的常量都没能 import 进来. 而这只发生在用了 multiprocess 的分支, 我怀疑是不是多进程中的 target method 在运行时会丢失 import.
    julyclyde
        4
    julyclyde  
       Apr 25, 2016
    循环 import 也没啥问题吧?为什么 multiprocessing 那么穷讲究?
    yetone
        5
    yetone  
       Apr 25, 2016
    @fds 是你不会 Python ,不要乱吐槽,太丢人了。。
    kamushin
        6
    kamushin  
    OP
       Apr 25, 2016
    @julyclyde 倒是和 multiprocessing 没啥关系. 只是循环 import 的时候, 包名和类名冲突覆盖了.
    fds
        7
    fds  
       Apr 25, 2016
    @yetone 吐个槽有啥丢人的…… 比如像下面网址中的问题,要不就是改 sys.path 要不就是用 python -m 参数,多麻烦
    ref : http://stackoverflow.com/questions/72852/how-to-do-relative-imports-in-python
    SmiteChow
        8
    SmiteChow  
       Apr 25, 2016
    循环引用可以通过拆分 py 文件的方式解决
    zonghua
        9
    zonghua  
       Apr 26, 2016 via iPhone
    会的,当初学习 python 的时候就发现了这个问题困扰我好久
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2812 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 53ms · UTC 07:44 · PVG 15:44 · LAX 00:44 · JFK 03:44
    ♥ Do have faith in what you're doing.