#! /usr/bin/env python
#encoding=utf8
"""
this script purpose is test __iter__ method
xiao mao write @ 2010-06-05
"""
class A:
def __init__(self,n):
self.n=n
def __iter__(self):
n=self.n
while n:
m=n%2
n/=2
print "--%s,%s"%(m,n)
yield m
print "=========="
for i in A(5):
print i
class B(dict):
def __init__(self):
self["a"]="a"
self["aa"]="aa"
self["1"]=1
b=B()
for k,v in b.iteritems():
print k,v
if b.has_key("b"):
print "has b"
elif b.has_key("aa"):
print "has aa"
else:
print "ddddd"
print type(b)
print isinstance(b,dict)