Python: Problem with local modules shadowing global modules

后端 未结 2 456
無奈伤痛
無奈伤痛 2020-12-30 05:41

I\'ve got a package set up like so:

packagename/
    __init__.py
    numbers.py
    tools.py
    ...other stuff

Now inside tools.py

相关标签:
2条回答
  • 2020-12-30 05:58

    absolute and relative imports can be used since python2.5 (with __future__ import) and seem to be what you're looking for.

    0 讨论(0)
  • 2020-12-30 06:01

    I try to avoid shadowing the standard library. How about renaming your module to "_numbers.py" ?

    And of course, you could still do:

    import _numbers as numbers
    
    0 讨论(0)
提交回复
热议问题