Please, help me to find a way how to resolve my problem. I have file structure like this
/j/
lib/
__init__.py
ftpserver.py
utils/
__init__.py
mogno.py
My.py
__init__.py
jftpd.py
in ftpserver.py I have a class which is the base class for some class in My.py
I mean:
# ftpserver.py
class foo()
...
and My.py is something like this:
# My.py
class bar(foo)
...
what I want is to use all my modules in jftpd.py. But I cannot find a way to accomplish this. I am doing something like this:
# jftpd.py
import lib.ftpserver
import utils.My
***some usage of my classes***
And interpreter return me
NameError: name 'foo' is not defined
It could be a good solutions to use relative import in My.py:
from ..lib.ftpserver import foo
but this also is not working method because of relative import, which is not allowed in python. In spite of numerous examples of relative import i have found, I get an error:
ValueError: Attempted relative import in non-package
executing something like:
from ..lib.ftpserver import *
Can anybody help me?
Try
from lib.ftpserver import foo. I can’t see any reason why that wouldn’t work. There’s no need for the..element.Make sure you import your original class where you define your inhereted one. For example: