Created
October 26, 2012 18:28
-
-
Save greggyNapalm/3960530 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
class Reg(object): | |
__all__ = set() | |
__t_pos__ = 0 | |
def __init__(self): | |
self.__class__.__all__.add(self) | |
def __iter__(self): | |
for inst in self.__class__.__all__: | |
return iter(self.__class__.__all__) | |
@staticmethod | |
def ping(): | |
return 'pong' | |
x = Reg() | |
y = Reg() | |
z = Reg() | |
print Reg.__all__ | |
print Reg.ping() | |
for i in Reg: | |
print i | |
# I got on cpython 2.7.3: | |
set([<__main__.Reg object at 0x105700590>, <__main__.Reg object at 0x1057005d0>, <__main__.Reg object at 0x105700610>]) | |
pong | |
Traceback (most recent call last): | |
File "./oop.py", line 98, in <module> | |
for i in Reg: | |
TypeError: 'type' object is not iterable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment