Created
July 2, 2011 04:27
-
-
Save karanparikh/1059735 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# global scope these variables so that | |
# we can use them throughout our code | |
Car = None | |
Bus = None | |
# | |
# exciting stuff happening here | |
# | |
# now, based on the variable vehicle | |
# we want to import a specific module | |
if vehicle == "car": | |
# equivalent to: from vehicle.four_wheels.car import Car | |
_Car = __import__("vehicle.four_wheels.car", globals(), locals(), ["Car"]) | |
Car = _Car.Car | |
if vehicle == "bus": | |
# equivalent to: from vehicle.four_wheels.bus import Bus | |
_Bus = __import__("vehicle.four_wheels.bus", globals(), locals(), ["Bus"]) | |
Bus = _Bus.Bus | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment