Skip to content

Instantly share code, notes, and snippets.

@awarrenlove
Created October 27, 2015 18:34
Show Gist options
  • Save awarrenlove/5d84295123a2345b276c to your computer and use it in GitHub Desktop.
Save awarrenlove/5d84295123a2345b276c to your computer and use it in GitHub Desktop.
Python Attribute with Space
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