Skip to content

Instantly share code, notes, and snippets.

@makmanalp
Created June 7, 2016 02:27
Show Gist options
  • Save makmanalp/34c8762109aa8ec991aaa786ee4bb8ff to your computer and use it in GitHub Desktop.
Save makmanalp/34c8762109aa8ec991aaa786ee4bb8ff to your computer and use it in GitHub Desktop.
Code in the body of a class - 12
In [1]: class Foo(object):
...: for i in range(3):
...: setattr(Foo, "x"+str(i), i)
...:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-bcc534efdfb8> in <module>()
----> 1 class Foo(object):
2 for i in range(3):
3 setattr(Foo, "x"+str(i), i)
4
<ipython-input-1-bcc534efdfb8> in Foo()
1 class Foo(object):
2 for i in range(3):
----> 3 setattr(Foo, "x"+str(i), i)
4
NameError: name 'Foo' is not defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment