Python error: AttributeError: 'module' object has no attribute

前端 未结 4 1276
梦如初夏
梦如初夏 2020-11-29 07:15

I\'m totally new to Python and I know this question was asked many times, but unfortunately it seems that my situation is a bit different... I have created a package (or so

4条回答
  •  情深已故
    2020-11-29 07:50

    When you import lib, you're importing the package. The only file to get evaluated and run in this case is the 0 byte __init__.py in the lib directory.

    If you want access to your function, you can do something like this from lib.mod1 import mod1 and then run the mod12 function like so mod1.mod12().

    If you want to be able to access mod1 when you import lib, you need to put an import mod1 inside the __init__.py file inside the lib directory.

提交回复
热议问题