Skip to content

Instantly share code, notes, and snippets.

@karanparikh
Created July 2, 2011 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karanparikh/1059735 to your computer and use it in GitHub Desktop.
Save karanparikh/1059735 to your computer and use it in GitHub Desktop.
# 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