Python Can't Find Class Even Though The Import Was Successful
I have some folder: /home/tom/my_module. In my_module directory I have: __init__.py (empty file) my_class.py class HelloWorldExample(object): @staticmethod def someMethod(
Solution 1:
When doing import my_module
you're importing the module and it will be available as my_module
.
If you want to access something defined in your module you will need to access it on the module ex: my_module.thing_in_my_module
.
In your example that would translate to:
importmy_modulex= my_module.HelloWorldExample()
But you could also do:
from my moduleimportHelloWorldExamplex= HelloWorldExample()
This imports the class directly rather than the module.
See https://docs.python.org/3/tutorial/modules.html#packages for more information on packages and imports.
Post a Comment for "Python Can't Find Class Even Though The Import Was Successful"