Thursday, January 7, 2010

import只是一次

下面是测试过程:

In [7]: import sys

In [8]: os
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)

/home/jessinio/data/workspace/project/<ipython console> in <module>()

NameError: name 'os' is not defined

In [9]: sys.getrefcount( sys.modules['os'] )
Out[9]: 58

In [10]: import os

In [11]: sys.getrefcount( sys.modules['os'] )
Out[11]: 59

In [12]: id( sys.modules['os'] )
Out[12]: 3078271308L

In [13]: id( os )
Out[13]: 3078271308L

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.