Created
January 12, 2012 16:44
-
-
Save matschaffer/1601533 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
*.pyc |
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
from uglycode import run | |
results = run({'override': 'was overridden'}) | |
print results[0] | |
print results[1] |
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
def run(overrides): | |
__params__ = __import__('params') | |
for name in dir(__params__): | |
value = getattr(__params__, name) | |
if isinstance(value, (int, long, basestring)): | |
globals()[name] = value | |
for var, val in overrides.iteritems(): | |
globals()[var] = val | |
# Don't want to edit below this line | |
output = [] | |
output.append("override %s" % (override)) | |
output.append("default %s" % (default)) | |
if False: | |
override='was some local crap' | |
return output |
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
hairy = __import__('original') | |
hairy.override = 'was overridden' | |
results = hairy.run() | |
print results[0] | |
print results[1] |
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
override = 'was not overridden' | |
default = 'was a default' | |
def run(): | |
# Don't want to edit below this line | |
output = [] | |
output.append("override %s" % (override)) | |
output.append("default %s" % (default)) | |
if False: | |
override='was some local crap' | |
return output |
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
override = 'was not overridden' | |
default = 'was a default' |
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
Python 2.7.1 |
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
override was overridden | |
default was a default |
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
def run(overrides): | |
# This works | |
from params import * | |
# This doesn't seem to | |
# override = 'was not overridden' | |
# default = 'was a default' | |
for var, val in overrides.iteritems(): | |
locals()[var] = val | |
# Don't want to edit below this line | |
output = [] | |
output.append("override %s" % (override)) | |
output.append("default %s" % (default)) | |
if False: | |
override='was some local crap' | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment