I have two files in the same location namely 'hello-depend.py' and 'second-package.py'
hello-depend.py
class HelloDepend():
def depend():
print "depend"
second-package.py
from hello-depend import HelloDepend
class SecondPackage():
def second():
print "second"
h = HelloDepend()
h.depend()
if \__name__ == '\__main__':
s = SecondPackage()
s.second()
I need to create object for hello-depend.py from second-package.py. i tied with above method. But i am getting 'syntax error' while importing 'hello-depend'.
Error:
File "second-package.py", line 1
import hello-depend
^
SyntaxError: invalid syntax
So i tried with below method.
import importlib
importlib.import_module('hello-depend')
but i am getting "global name 'HelloDepend' not defined'
Please help me in solving this.
Note: I need to do this without changing file name.
-from module name and use_then try.