Reputation: 1620
So if I have 2 files that look like this:
File 1
import class1
import method1
def method2(something):
result = method1(classname=class1)
File 2
def method1(classname):
some_result = classname.resultfinder
return some_result
Will this work?
I mean, since I am not importing class1 in the file where method1 lives, but method1 still ends up using class1. Will method1 have access to class1 via the import made in File 1 where method 1 is imported to?
Upvotes: 2
Views: 213
Reputation: 43446
It doesn't quite look right--you don't exactly "import class1", you more import a module (in a file) that contains class1, or a module that contains method1. So I'd expect to see more like
from file2 import method1
from file3 import class1
Also, method1
doesn't so much take a class name as a class object. Or should that be a class instance object? Sorry if I'm being picky, but hopefully it's educational to consider the distinction.
Upvotes: 0
Reputation: 11744
What happened when you tried it?
Note that your import of method1
is wrong. Apart from that --- yes, you do not need to import everything. Do you think the standard library imports your stuff whenever you use it? ;-)
Upvotes: 2
Reputation: 83250
I think that should be fine - imagine having to import every possible type that could be passed to a function at runtime. I don't think a "dynamic" language like that would last very long.
Upvotes: 1