Python Stackoverflow 经典问题
What does the “yield” keyword do?
What is a metaclass in Python?
How do I check whether a file exists using Python?
Does Python have a ternary conditional operator?
Calling an external command in Python
What does if __name__ == “__main__”: do?
How to make a chain of function decorators in继续阅读 »
也许你会偶然发现Python的多线程程序使用Ctrl-C杀不掉,必须拿到pid用kill -9才能干掉,研究这个问题的原因可以使得对Python多线程的信号处理及线程的退出机制有更好的理解。
假如有一个Python写成的用多线程模拟生产者-消费者的程序,代码如下:
class Producer(threading.Thread):
def run(self):
global count
while True:
if cond.acquire():
if count > 1000:
cond.wa继续阅读 »
1. Pythonic Thinking
1.1 know which version of python you're using
two major python version;
multiple popular runtimes for python: cpython, jython, ironpython, pypy, etc;
be sure that the command line for running python on your system is the version you want;
prefer python 3 in your next project;继续阅读 »