I’ll show a small peice of code at first:
:::python
>>> def foo(a=[]):
... a.append(1)
... print(a)
...
>>> foo()
[1]
>>> foo()
[1, 1]
>>> foo()
[1, 1, 1]
>>> foo
<function foo at 0x7efc48708bf8>
I was confused by this when first met it years ago. A lot of people, me
included, may think that list a should always be [1] and why it behaviors like a
global variable.
Everything is an object
We frequently see this quote but it’s not easy to understand.
In python, a function is an object too. This object is created after definition.
And the function name is just like a reference to the object. And the default
parameter of the function is also determined at the same time.
I started a small project based on tornado and mongodb last week, now I’d like
to write a summary about it since most functions are finished.
Why start this project
We used bugzilla frequently but the traffic to bugzilla is very slow.
It uses openid to login and the authentication cookies last very short.
Too many irrelevant products.
Goal of the project
Using curl to search the bugzilla easily. You can search by keywords, or email.
Can easily get latest reported bugs of a specific product.
How to?
Our bugzilla enabled the xmlrpc api so it’s very easy to fetch data using
xmlrpcclient library. I chose to store data with mongodb.
Wrote the web server based on tornado. Parsed the requests and queried the
mongodb and then wrote back the data.
Code repo:
github.com/zxdvd/scripts/tree/master/bugzilla
I didn’t use a independent repo since there isn’t too much codes.