python3.x - python3.4中怎么导入__init__.py中的类
PHPz
PHPz 2017-04-17 15:01:15
0
3
832

项目的结构时
lib------
      |--__init__.py
      |
      |--page.py

我在 __init__.py中定义了一个class A,请问怎么在page.py中导入这个类?
注意在python3.4环境中。

PHPz
PHPz

学习是最好的投资!

reply all(3)
Peter_Zhu

Use absolute_import

pythonfrom . import A
小葫芦

My test environmentpython 3.4
Questioner, I created a Project and tested it. The file structure is as follows:

project_test/

|---test.py
|---test

|---init.py

It can be seen that test is a package
__init__.py:

pythonclass module_1:
    print('This is a test!')
    pass

When I import test in test.py, run
The output result is:
This is a test
Note that when importthispackage occurs, the class is automatically instantiated. In this way, for your question, you should just call it directly~

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!