Reputation: 322
So in python you can do from foo import bar
, this gets the bar from foo but how can I get something from inside of the bar object
I.e
from foo import bar.childDef # gets childDef() from inside of bar
Because normally you would have to type bar.childDef()
with a regular import statement using from,
however I just wanna use childDef()
instead of bar.childDef()
Sorry if this is a confusing or just bad question in general, I'm just curious.
Upvotes: 0
Views: 35
Reputation: 2782
## foo.py
class bar:
def childDef ():
print('Child Def')
And import from another script,
from foo import bar
# import method
imported_fun = bar.childDef
#call method
bar.childDef() # or imported_fun()
Upvotes: 1