I am getting this error when I try to import a another python class in a different directory.
this is how my folder structure looks like:
main
/prerequisites
- __init__.py
- BitesizeClusterInfo.py
- ComponentStatus.py
__init__.py
BitesizeDecorator.py
BitesizeImp.py
BitesizeInterface.py
constants.py
execute.py
main.py
I am trying to import BitesizeDecorator.py
from BitesizeClusterInfo.py
and I get this error:
Traceback (most recent call last): File "ComponentStatus.py", line 1, in from BitesizeDecorator import BitesizeDecorator ImportError: No module named BitesizeDecorator
And this is how my code snippet for BitesizeClusterInfo.py
looks like:
import os
from BitesizeDecorator import BitesizeDecorator
from execute import Execute
class BitesizeClusterInfo(BitesizeDecorator):
def __init__(self, bitesize):
super(BitesizeClusterInfo, self).__init__(bitesize)
def test(self):
super(BitesizeClusterInfo, self).test()
# add command below
print("\n[1] - Checking cluster info...\n")
# grep the output for ease of reading
cmd = "kubectl cluster-info | grep -E 'master|DNS'"
print(Execute.check_if_exists(cmd))
Can someone please help me solve this?
这将是:
from main.BitesizeDecorator import BitesizeDecorator
You can change the position of the file BitesizeClusterInfo.py
to the main folder to make you line work.
Or use
from main.BitesizeDecorator import BitesizeDecorator
and if your main folder is the project source :
from main.BitesizeDecorator import BitesizeDecorator
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.