摘要: class Bird: def __init__(self): self.eaten = False def eat(self): if(self.eaten == False): self.eaten = True print("Eating now") else: print("no,thinks") @staticmethod def fly(): print('''I believe I can fly, I bel... 阅读全文
posted @ 2013-05-30 00:24 youJumpILook 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 在python3.x中,exec已经变成函数,并且和eval的调用形式基本相同。1 """2 在利用exec执行动态密码时,为了安全期间,通过利用字典作为命名空间3 """4 from math import sqrt5 scope = {}6 exec "sqrt = 1" in scope #这一段在交互式解释器会返回False,应该为exec("sqrt = 1",scope)7 sqrt(4) #返回2.0因为之前的一句仅仅在自己的局部命名空间(scope)里执行, 阅读全文
posted @ 2013-05-30 00:00 youJumpILook 阅读(598) 评论(0) 推荐(0) 编辑