from <module> import *
takes all names in a module (those that don't start with a _
or everything listed in <module>.__all__
and assigns those names as globals in your current module.
If two modules define the same name, that means that the last one imported this way wins; cleanup = rflib.cleanup
is replaced by cleanup = Rpi.GPIO.cleanup
with the second from Rpi.GPIO import *
statement.
You generally want to avoid using from <module> import *
. Import specific names, or just the module itself.
In this case, you can do:
from rflib import cleanup as rflib_cleanup
from Rpi.GPIO import cleanup as rpigpio_cleanup
which would bind those two functions as different names.
Or you could just import the modules:
import rflib
from Rpi import GPIO
which gives you only the rflib
and GPIO
names, each a reference to the module object, so now you can reference each of the cleanup
functions as attributes on those modules:
rflib.cleanup()
GPIO.cleanup()
If you need to use a lot of names from either module, the latter style is preferred because that limits the number of imports you need to do, keeps your namespace clean and un-cluttered, and gives you more context whereever those names are used in your code.