Python为什么__init__.py?

时间:2018-01-17 11:17:34

标签: python cmd pycharm init

我在__init__.py目录中遇到了y_init_.pyhelloWord.pysome_modules所有关于Python的问题,并且main.py是相同的目录为some_modules

__init__.py中的

print('************')
y__init__.py中的

if __name__ == '__main__':
    print('__init__.py directly exectuted!')
else:
    print("be imported!")
helloWord.py中的

import y__init__
print("hello word!")
main.py中的

from some_modules import helloWord

如下图所示:

**directory**

如果我在PyCharm中运行main.py,main.py可以直接运行,并输出:

************
be imported!
hello word!

但如果我在dos中运行main.py,那么找不到模块'y__init__'的错误,为什么会发生这种情况? :

  ************
  File "G:\seniorWorksHand\PythonLecture\python_work\main.py", line 1, in <module>
    from some_modules import helloWord
  File "G:\seniorWorksHand\PythonLecture\python_work\some_modules\helloWord.py", line 1, in <module>
    import y__init__
ModuleNotFoundError: No module named 'y__init__'

当我得到帮助时,我会非常感激,非常感谢你们!

0 个答案:

没有答案
相关问题