Created
October 27, 2015 18:34
-
-
Save awarrenlove/5d84295123a2345b276c to your computer and use it in GitHub Desktop.
Python Attribute with Space
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
import sys | |
module = sys.modules[__name__] | |
setattr(module, 'this has a space', 'just_a_value') | |
#This raises a SyntaxError | |
#print(module.this has a space) | |
#This works as expected and writes 'just_a_value' | |
print(getattr(module, 'this has a space')) | |
setattr(module, 'this_has_no_space', 'second_value') | |
#This works as expected | |
print(module.this_has_no_space) | |
#So does this | |
print(getattr(module, 'this_has_no_space')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment