I have been using tornado for nearly 2 years! Now, I begin to read the resource code, and find some code can be more beautiful. show a instance as follows:
> I have been using tornado for nearly 2 years! Now, I begin to read the > resource code, and find some code can be more beautiful. show a instance > as follows:
hehe, thanks for your response. I read your blog in "http://chenxiaoyu.org". Good easy! nginx+tornado are also be used in our projject and they work perfect. an extra question: how to give advices or bugs to the maintainer of tornado. it seems terrible to use " http://www.apache.org/licenses/LICENSE-2.0".
>> I have been using tornado for nearly 2 years! Now, I begin to read the >> resource code, and find some code can be more beautiful. show a instance >> as follows:
> hehe, thanks for your response. > I read your blog in "http://chenxiaoyu.org". Good easy! nginx+tornado > are also be used in our projject and they work perfect. > an extra question: how to give advices or bugs to the maintainer of > tornado. it seems terrible to use " > http://www.apache.org/licenses/LICENSE-2.0".
>>> I have been using tornado for nearly 2 years! Now, I begin to read the >>> resource code, and find some code can be more beautiful. show a instance >>> as follows:
> in my views, if getattr(self, "_db", None) is not None: can be > replaced to if hasattr(self,"_db"):
Actually that's not the same test at all. hasattr(self, "_db") will be True even if self._db == None.
>>> class Foo (object):
... def __init__ (self): ... self.bar = None ...
>>> f = Foo () >>> hasattr (f, "bar") True
Therefore you must have getattr (self, "_db") == None. Except perhaps there is no attribute _db, which will throw an exception, so you must have a default:
> Therefore you must have getattr (self, "_db") == None. Except perhaps > there is no attribute _db, which will throw an exception, so you must > have a default:
> if getattr(self, "_db", None) is not None
> And now you are back to the original code.
> Regards, > Cliff
sorry for my fault and misunderstand. I did not think it deeply and it's all my fault. thanks for the points. Thanks!