Search code examples
pythonpython-3.xstructurepython-importpython-packaging

An idea of importing an user define python package


The structure needs for python 3.8+

That x.py contains x class with a 'display' method enter image description here

concept one:

from p_abcd import a as A

''' call display '''

A.x.x().display()

Got an error

Traceback (most recent call last):

File "w.py", line 4, in

A.x.x().display()

AttributeError: module 'p_abcd.a' has no attribute 'x'

concept two:

import p_abcd.a as A

''' call display '''

A.x.x().display()

Got the same error


Solution

  • You can import only .py files. Not folders.

    So you need something like

    from p_abcd.a import x
    x.display()