How do I import from a file in the current directory in Python 3?

后端 未结 2 1146
耶瑟儿~
耶瑟儿~ 2020-12-29 19:29

In python 2 I can create a module like this:

parent
->module
  ->__init__.py (init calls \'from file import ClassName\')
    file.py
    ->class Cla         


        
2条回答
  •  醉话见心
    2020-12-29 20:18

    Try import it this way:

    from .file import ClassName
    

    See here more info on "Guido's decision" on imports in python 3 and complete example on how to import in python 3.

提交回复
热议问题