http://groups.google.com/group/comp.lang.python/browse_thread/thread/fe6430e7980e2a96?hl=en#
if brief . the python import statement may search module in current path first, and files in the same module has very weak relation such as the followiing example that email.py was used in two place and python finds the wrong one
bash$ touch email.py
bash$ python
...
>>> import smtplib
Traceback (most recent call last):
File "
File "/usr/lib/python2.5/smtplib.py", line 46, in
import email.Utils
ImportError: No module named Utils
the second is about generator expression, the variable in the clause is not evaluated or stored immediately and may lead a lot of error. To avoid this, list comprehension or closure are the solutions.
http://yz.mit.edu/wp/2010/01/14/bitten-by-python-scoping/
As I use python much, I always can find something strange as I use it :<
沒有留言:
張貼留言