I have two functions organized in two files. E.g.
file a.py
import b
def a():
print "a"
if __name__ == "__main__":
b.b()
file b.py
import a # this is what I want to eliminate
def b():
a.a() # could I invoke a from a.py with simply a()?
Is it possible to invoke a from b.py directly without importing a and just with a simple name a() instead of the fully qualified one?
Thanks and Best Regards!
No. How would Python know where
ais supposed to be? You might have thousands of Python files on your system and mean any of them.As you say, you have your code organized in two files. Having every function in every file on your entire system be available at all times wouldn’t be very organized.
But you can do this:
This plucks a single function from your module, so you don’t need to use the module name to call it.