Erick Gallani
Erick Gallani

Reputation: 809

Dealing with imports on sub-modules in python

I have the following structure

|-- package/
|   |-- __init__.py
|   |-- module.py
|   |-- subpackage/
|   |   |-- __init__.py
|   |   |-- sub_module.py

My sub_module.py has one method definition, for example:

sub_module.py

def my_sub_method():

And my module.py have a lot of classes. module.py

class Class1():
class Class2():
class Class3():
class Class4():

It this possible to do the following import?

sub_module.py

from package.module import Class1

And on main module

module.py

from subpackage.sub_module import my_sub_method

I tried do this import but didn't worked. I'm wondering if the problem is the circular module import.

Upvotes: 1

Views: 46

Answers (1)

YFP
YFP

Reputation: 337

Have you had a look at this stackoverflow post?

Importing modules from parent folder

This describes an array of ways to accomplish what I believe you are looking for.

HTHs

Thanks,

//P

Upvotes: 1

Related Questions