TableOfContents

Include(ZPyUGnav)

[奇用]嵌入式函式

沈崴 <[email protected]>
reply-to        [email protected]
to      python-cn`CPyUG`华蟒用户组 <[email protected]>
date    Wed, Oct 15, 2008 at 16:37
subject [CPyUG:68306] 新手提问, 为什么有中间变量和没有中

现象

   1 import sys
   2 def test():
   3        m = type(sys)('<string>')
   4        exec '''\
   5 a = 'hello world!'
   6 def print_a():
   7        print a''' in m.__dict__
   8        return m
   9 
  10 test().print_a() # -> None
  11 
  12 temp = test()
  13 temp.print_a() # -> hello world!

理解

ZoomQuiet
  • 这又是魔术之一,在函式中制造函式,没有运行函式前,名利空间中是没有那个 print_a() 的这不是中间变量,根本就是 运行时 mix-in


反馈

创建 by -- ZoomQuiet [DateTime(2008-10-15T09:18:32Z)]

PageComment2

[:/PageCommentData:PageCommentData]