Python论坛  - 讨论区

标题:[python-chinese] 最近在研究python源码,有个问题搞不明白,求教

2006年11月29日 星期三 10:56

libing imlibing在163.com
星期三 十一月 29 10:56:55 HKT 2006

hello,大家好,小弟最近在研究python源码,有个问题搞不明白,求教!

对一段代码:
x = 1
def foo():
 y = x+1
 print x
 print y
foo()
print x

我打印出它的code object 结构出来分析:
====================================================
co_names : ('x', 'foo')
co_varnames : ()
co_freevars : ()
co_cellvars : ()
  1           0 LOAD_CONST               0 (1)
              3 STORE_NAME               0 (x)

  2           6 LOAD_CONST               1 ()

nest code object begin <<<<<
co_names : ('x',)
co_varnames : ('y',)
co_freevars : ()
co_cellvars : ()
  3           0 LOAD_GLOBAL              0 (x)
              3 LOAD_CONST               1 (1)
              6 BINARY_ADD          
              7 STORE_FAST               0 (y)

  4          10 LOAD_GLOBAL              0 (x)
             13 PRINT_ITEM          
             14 PRINT_NEWLINE       

  5          15 LOAD_FAST                0 (y)
             18 PRINT_ITEM          
             19 PRINT_NEWLINE       
             20 LOAD_CONST               0 (None)
             23 RETURN_VALUE        
nest code object end >>>>>

              9 MAKE_FUNCTION            0
             12 STORE_NAME               1 (foo)

  6          15 LOAD_NAME                1 (foo)
             18 CALL_FUNCTION            0
             21 POP_TOP             

  7          22 LOAD_NAME                0 (x)
             25 PRINT_ITEM          
             26 PRINT_NEWLINE       
             27 LOAD_CONST               2 (None)
             30 RETURN_VALUE        
====================================================

在外层存x值的时候的byte code是              3 STORE_NAME               0 (x)
在ceval.c源码里这段对应的是
  case STORE_NAME:
   w = GETITEM(names, oparg);
   v = POP();
   if ((x = f->f_locals) != NULL) {
    if (PyDict_CheckExact(x))
     err = PyDict_SetItem(x, w, v);
    else
     err = PyObject_SetItem(x, w, v);
    Py_DECREF(v);
    if (err == 0) continue;
    break;
   }
   PyErr_Format(PyExc_SystemError,
         "no locals found when storing %s",
         PyObject_REPR(w));
   break;

这是存在foo外层frame的的local里吧?但是外层byte code里x没有在co_varnames里面,那么它就应该在global里吧?
foo里面又如何从外层传进来的global表里查到x的值呢?我怎么也找不到foo外面将x赋值到global表的部分,求教了!

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年11月29日 星期三 11:01

libing imlibing在163.com
星期三 十一月 29 11:01:50 HKT 2006

代码排版不好,晕死,不好意思
重排一下:

x = 1
def foo():
      y = x+1
      print x
      print y
foo()
print x



----- Original Message ----- 
From: "libing" <imlibing在163.com>
To: <python-chinese在lists.python.cn>
Sent: Wednesday, November 29, 2006 10:56 AM
Subject: [python-chinese] 最近在研究python源码,有个问题搞不明白,求教!


> hello,大家好,小弟最近在研究python源码,有个问题搞不明白,求教!
> 
> 对一段代码:
> x = 1
> def foo():
>  y = x+1
>  print x
>  print y
> foo()
> print x
> 
> 我打印出它的code object 结构出来分析:
> ====================================================
> co_names : ('x', 'foo')
> co_varnames : ()
> co_freevars : ()
> co_cellvars : ()
>   1           0 LOAD_CONST               0 (1)
>               3 STORE_NAME               0 (x)
> 
>   2           6 LOAD_CONST               1 ()
> 
> nest code object begin <<<<<
> co_names : ('x',)
> co_varnames : ('y',)
> co_freevars : ()
> co_cellvars : ()
>   3           0 LOAD_GLOBAL              0 (x)
>               3 LOAD_CONST               1 (1)
>               6 BINARY_ADD          
>               7 STORE_FAST               0 (y)
> 
>   4          10 LOAD_GLOBAL              0 (x)
>              13 PRINT_ITEM          
>              14 PRINT_NEWLINE       
> 
>   5          15 LOAD_FAST                0 (y)
>              18 PRINT_ITEM          
>              19 PRINT_NEWLINE       
>              20 LOAD_CONST               0 (None)
>              23 RETURN_VALUE        
> nest code object end >>>>>
> 
>               9 MAKE_FUNCTION            0
>              12 STORE_NAME               1 (foo)
> 
>   6          15 LOAD_NAME                1 (foo)
>              18 CALL_FUNCTION            0
>              21 POP_TOP             
> 
>   7          22 LOAD_NAME                0 (x)
>              25 PRINT_ITEM          
>              26 PRINT_NEWLINE       
>              27 LOAD_CONST               2 (None)
>              30 RETURN_VALUE        
> ====================================================
> 
> 在外层存x值的时候的byte code是              3 STORE_NAME               0 (x)
> 在ceval.c源码里这段对应的是
>   case STORE_NAME:
>    w = GETITEM(names, oparg);
>    v = POP();
>    if ((x = f->f_locals) != NULL) {
>     if (PyDict_CheckExact(x))
>      err = PyDict_SetItem(x, w, v);
>     else
>      err = PyObject_SetItem(x, w, v);
>     Py_DECREF(v);
>     if (err == 0) continue;
>     break;
>    }
>    PyErr_Format(PyExc_SystemError,
>          "no locals found when storing %s",
>          PyObject_REPR(w));
>    break;
> 
> 这是存在foo外层frame的的local里吧?但是外层byte code里x没有在co_varnames里面,那么它就应该在global里吧?
> foo里面又如何从外层传进来的global表里查到x的值呢?我怎么也找不到foo外面将x赋值到global表的部分,求教了!
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年11月29日 星期三 11:03

刘鑫 march.liu在gmail.com
星期三 十一月 29 11:03:01 HKT 2006

Ó¦¸ÃÊÇÕâÌõ
  3           0 LOAD_GLOBAL              0 (x)
ÎÒ²ÂÏëÊǽâÊÍÆ÷±àÒëfooµÄʱºò£¬ÔÚfooÄÚ²¿ÕÒ²»µ½xµÄ¸³Öµ£¬¾ÍÖ±½ÓÔÚ×îÇ°Ãæ²åÈëÁËÕâ¸öÖ¸Áî¡£

2006/11/29, libing <imlibing在163.com>:
>
> hello,´ó¼ÒºÃ£¬Ð¡µÜ×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡
>
> ¶ÔÒ»¶Î´úÂ룺
> x = 1
> def foo():
> y = x+1
> print x
> print y
> foo()
> print x
>
> ÎÒ´òÓ¡³öËüµÄcode object ½á¹¹³öÀ´·ÖÎö£º
> £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
> co_names : ('x', 'foo')
> co_varnames : ()
> co_freevars : ()
> co_cellvars : ()
>   1           0 LOAD_CONST               0 (1)
>               3 STORE_NAME               0 (x)
>
>   2           6 LOAD_CONST               1 (> file "string", line 2>)
>
> nest code object begin <<<<<
> co_names : ('x',)
> co_varnames : ('y',)
> co_freevars : ()
> co_cellvars : ()
>   3           0 LOAD_GLOBAL              0 (x)
>               3 LOAD_CONST               1 (1)
>               6 BINARY_ADD
>               7 STORE_FAST               0 (y)
>
>   4          10 LOAD_GLOBAL              0 (x)
>              13 PRINT_ITEM
>              14 PRINT_NEWLINE
>
>   5          15 LOAD_FAST                0 (y)
>              18 PRINT_ITEM
>              19 PRINT_NEWLINE
>              20 LOAD_CONST               0 (None)
>              23 RETURN_VALUE
> nest code object end >>>>>
>
>               9 MAKE_FUNCTION            0
>              12 STORE_NAME               1 (foo)
>
>   6          15 LOAD_NAME                1 (foo)
>              18 CALL_FUNCTION            0
>              21 POP_TOP
>
>   7          22 LOAD_NAME                0 (x)
>              25 PRINT_ITEM
>              26 PRINT_NEWLINE
>              27 LOAD_CONST               2 (None)
>              30 RETURN_VALUE
> £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
>
> ÔÚÍâ²ã´æxÖµµÄʱºòµÄbyte codeÊÇ              3 STORE_NAME               0 (x)
> ÔÚceval.cÔ´ÂëÀïÕâ¶Î¶ÔÓ¦µÄÊÇ
>   case STORE_NAME:
>    w = GETITEM(names, oparg);
>    v = POP();
>    if ((x = f->f_locals) != NULL) {
>     if (PyDict_CheckExact(x))
>      err = PyDict_SetItem(x, w, v);
>     else
>      err = PyObject_SetItem(x, w, v);
>     Py_DECREF(v);
>     if (err == 0) continue;
>     break;
>    }
>    PyErr_Format(PyExc_SystemError,
>          "no locals found when storing %s",
>          PyObject_REPR(w));
>    break;
>
> ÕâÊÇ´æÔÚfooÍâ²ãframeµÄµÄlocalÀï°É£¿µ«ÊÇÍâ²ãbyte codeÀïxûÓÐÔÚco_varnamesÀïÃ棬ÄÇôËü¾ÍÓ¦¸ÃÔÚglobalÀï°É£¿
> fooÀïÃæÓÖÈçºÎ´ÓÍâ²ã´«½øÀ´µÄglobal±íÀï²éµ½xµÄÖµÄØ£¿ÎÒÔõôҲÕÒ²»µ½fooÍâÃ潫x¸³Öµµ½global±íµÄ²¿·Ö£¬Çó½ÌÁË£¡
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese




-- 
»¶Ó­·ÃÎÊ£º
http://blog.csdn.net/ccat

ÁõöÎ
March.Liu
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061129/91ee3b73/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年11月29日 星期三 11:13

libing imlibing在163.com
星期三 十一月 29 11:13:51 HKT 2006

  3           0 LOAD_GLOBAL              0 (x)
ÕâÌõÊÇfoo´ÓglobalÀï²éxµÄ£¬globalÓÖÊÇ´ÓfooÍâÃæ´«½øÀ´µÄ£¬µ«ÊÇÎÊÌâÊÇÔÚfooÍâÃæûÓп´µ½ÍùglobalÉèxÖµµÄ´úÂ룬ÓеÄÖ»ÊÇ
              3 STORE_NAME               0 (x)
ÕâÌõ£¬ÕâÊÇÍùfooÍâÃæµÄlocal²åÊý¾ÝµÄ
  ----- Original Message ----- 
  From: ÁõöÎ 
  To: python-chinese在lists.python.cn 
  Sent: Wednesday, November 29, 2006 11:03 AM
  Subject: Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡


  Ó¦¸ÃÊÇÕâÌõ
    3           0 LOAD_GLOBAL              0 (x)
  ÎÒ²ÂÏëÊǽâÊÍÆ÷±àÒëfooµÄʱºò£¬ÔÚfooÄÚ²¿ÕÒ²»µ½xµÄ¸³Öµ£¬¾ÍÖ±½ÓÔÚ×îÇ°Ãæ²åÈëÁËÕâ¸öÖ¸Áî¡£


  2006/11/29, libing <imlibing在163.com>: 
    hello,´ó¼ÒºÃ£¬Ð¡µÜ×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡

    ¶ÔÒ»¶Î´úÂ룺
    x = 1
    def foo():
    y = x+1 
    print x
    print y
    foo()
    print x

    ÎÒ´òÓ¡³öËüµÄcode object ½á¹¹³öÀ´·ÖÎö£º
    £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
    co_names : ('x', 'foo')
    co_varnames : ()
    co_freevars : ()
    co_cellvars : ()
      1           0 LOAD_CONST               0 (1)
                  3 STORE_NAME               0 (x)

      2           6 LOAD_CONST               1 ()

    nest code object begin <<<<<
    co_names : ('x',)
    co_varnames : ('y',)
    co_freevars : ()
    co_cellvars : ()
      3           0 LOAD_GLOBAL              0 (x)
                  3 LOAD_CONST               1 (1) 
                  6 BINARY_ADD
                  7 STORE_FAST               0 (y)

      4          10 LOAD_GLOBAL              0 (x)
                 13 PRINT_ITEM
                 14 PRINT_NEWLINE

      5          15 LOAD_FAST                0 (y) 
                 18 PRINT_ITEM
                 19 PRINT_NEWLINE
                 20 LOAD_CONST               0 (None)
                 23 RETURN_VALUE
    nest code object end >>>>>

                  9 MAKE_FUNCTION            0 
                 12 STORE_NAME               1 (foo)

      6          15 LOAD_NAME                1 (foo)
                 18 CALL_FUNCTION            0
                 21 POP_TOP

      7          22 LOAD_NAME                0 (x) 
                 25 PRINT_ITEM
                 26 PRINT_NEWLINE
                 27 LOAD_CONST               2 (None)
                 30 RETURN_VALUE
    £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½

    ÔÚÍâ²ã´æxÖµµÄʱºòµÄbyte codeÊÇ              3 STORE_NAME               0 (x) 
    ÔÚceval.cÔ´ÂëÀïÕâ¶Î¶ÔÓ¦µÄÊÇ
      case STORE_NAME:
       w = GETITEM(names, oparg);
       v = POP();
       if ((x = f->f_locals) != NULL) {
        if (PyDict_CheckExact(x))
         err = PyDict_SetItem(x, w, v);
        else
         err = PyObject_SetItem(x, w, v);
        Py_DECREF(v);
        if (err == 0) continue;
        break;
       }
       PyErr_Format(PyExc_SystemError,
             "no locals found when storing %s",
             PyObject_REPR(w)); 
       break;

    ÕâÊÇ´æÔÚfooÍâ²ãframeµÄµÄlocalÀï°É£¿µ«ÊÇÍâ²ãbyte codeÀïxûÓÐÔÚco_varnamesÀïÃ棬ÄÇôËü¾ÍÓ¦¸ÃÔÚglobalÀï°É£¿
    fooÀïÃæÓÖÈçºÎ´ÓÍâ²ã´«½øÀ´µÄglobal±íÀï²éµ½xµÄÖµÄØ£¿ÎÒÔõôҲÕÒ²»µ½fooÍâÃ潫x¸³Öµµ½global±íµÄ²¿·Ö£¬Çó½ÌÁË£¡
    _______________________________________________
    python-chinese 
    Post: send python-chinese在lists.python.cn
    Subscribe: send subscribe to python-chinese-request在lists.python.cn 
    Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
    Detail Info: http://python.cn/mailman/listinfo/python-chinese 



  -- 
  »¶Ó­·ÃÎÊ£º
  http://blog.csdn.net/ccat

  ÁõöÎ
  March.Liu



------------------------------------------------------------------------------


  _______________________________________________
  python-chinese
  Post: send python-chinese在lists.python.cn
  Subscribe: send subscribe to python-chinese-request在lists.python.cn
  Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
  Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061129/d4a61607/attachment-0001.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年11月29日 星期三 11:17

libing imlibing在163.com
星期三 十一月 29 11:17:45 HKT 2006

LOAD_GLOBAL ¶ÔÓ¦µÄÔ´Â룺
  case LOAD_GLOBAL:
   w = GETITEM(names, oparg);
   if (PyString_CheckExact(w)) {
    /* Inline the PyDict_GetItem() calls.
       WARNING: this is an extreme speed hack.
       Do not try this at home. */
    long hash = ((PyStringObject *)w)->ob_shash;
    if (hash != -1) {
     PyDictObject *d;
     PyDictEntry *e;
     d = (PyDictObject *)(f->f_globals);
     e = d->ma_lookup(d, w, hash);
     if (e == NULL) {
      x = NULL;
      break;
     }
     x = e->me_value;
     if (x != NULL) {
      Py_INCREF(x);
      PUSH(x);
      continue;
     }
     d = (PyDictObject *)(f->f_builtins);
     e = d->ma_lookup(d, w, hash);
     if (e == NULL) {
      x = NULL;
      break;
     }
     x = e->me_value;
     if (x != NULL) {
      Py_INCREF(x);
      PUSH(x);
      continue;
     }
     goto load_global_error;
    }
   }
   /* This is the un-inlined version of the code above */
   x = PyDict_GetItem(f->f_globals, w);
   if (x == NULL) {
    x = PyDict_GetItem(f->f_builtins, w);
    if (x == NULL) {
      load_global_error:
     format_exc_check_arg(
          PyExc_NameError,
          GLOBAL_NAME_ERROR_MSG, w);
     break;
    }
   }
   Py_INCREF(x);
   PUSH(x);
   continue;
  ----- Original Message ----- 
  From: libing 
  To: python-chinese在lists.python.cn 
  Sent: Wednesday, November 29, 2006 11:13 AM
  Subject: Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡


    3           0 LOAD_GLOBAL              0 (x)
  ÕâÌõÊÇfoo´ÓglobalÀï²éxµÄ£¬globalÓÖÊÇ´ÓfooÍâÃæ´«½øÀ´µÄ£¬µ«ÊÇÎÊÌâÊÇÔÚfooÍâÃæûÓп´µ½ÍùglobalÉèxÖµµÄ´úÂ룬ÓеÄÖ»ÊÇ
                3 STORE_NAME               0 (x)
  ÕâÌõ£¬ÕâÊÇÍùfooÍâÃæµÄlocal²åÊý¾ÝµÄ
    ----- Original Message ----- 
    From: ÁõöÎ 
    To: python-chinese在lists.python.cn 
    Sent: Wednesday, November 29, 2006 11:03 AM
    Subject: Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡


    Ó¦¸ÃÊÇÕâÌõ
      3           0 LOAD_GLOBAL              0 (x)
    ÎÒ²ÂÏëÊǽâÊÍÆ÷±àÒëfooµÄʱºò£¬ÔÚfooÄÚ²¿ÕÒ²»µ½xµÄ¸³Öµ£¬¾ÍÖ±½ÓÔÚ×îÇ°Ãæ²åÈëÁËÕâ¸öÖ¸Áî¡£


    2006/11/29, libing <imlibing在163.com>: 
      hello,´ó¼ÒºÃ£¬Ð¡µÜ×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡

      ¶ÔÒ»¶Î´úÂ룺
      x = 1
      def foo():
      y = x+1 
      print x
      print y
      foo()
      print x

      ÎÒ´òÓ¡³öËüµÄcode object ½á¹¹³öÀ´·ÖÎö£º
      £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
      co_names : ('x', 'foo')
      co_varnames : ()
      co_freevars : ()
      co_cellvars : ()
        1           0 LOAD_CONST               0 (1)
                    3 STORE_NAME               0 (x)

        2           6 LOAD_CONST               1 ()

      nest code object begin <<<<<
      co_names : ('x',)
      co_varnames : ('y',)
      co_freevars : ()
      co_cellvars : ()
        3           0 LOAD_GLOBAL              0 (x)
                    3 LOAD_CONST               1 (1) 
                    6 BINARY_ADD
                    7 STORE_FAST               0 (y)

        4          10 LOAD_GLOBAL              0 (x)
                   13 PRINT_ITEM
                   14 PRINT_NEWLINE

        5          15 LOAD_FAST                0 (y) 
                   18 PRINT_ITEM
                   19 PRINT_NEWLINE
                   20 LOAD_CONST               0 (None)
                   23 RETURN_VALUE
      nest code object end >>>>>

                    9 MAKE_FUNCTION            0 
                   12 STORE_NAME               1 (foo)

        6          15 LOAD_NAME                1 (foo)
                   18 CALL_FUNCTION            0
                   21 POP_TOP

        7          22 LOAD_NAME                0 (x) 
                   25 PRINT_ITEM
                   26 PRINT_NEWLINE
                   27 LOAD_CONST               2 (None)
                   30 RETURN_VALUE
      £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½

      ÔÚÍâ²ã´æxÖµµÄʱºòµÄbyte codeÊÇ              3 STORE_NAME               0 (x) 
      ÔÚceval.cÔ´ÂëÀïÕâ¶Î¶ÔÓ¦µÄÊÇ
        case STORE_NAME:
         w = GETITEM(names, oparg);
         v = POP();
         if ((x = f->f_locals) != NULL) {
          if (PyDict_CheckExact(x))
           err = PyDict_SetItem(x, w, v);
          else
           err = PyObject_SetItem(x, w, v);
          Py_DECREF(v);
          if (err == 0) continue;
          break;
         }
         PyErr_Format(PyExc_SystemError,
               "no locals found when storing %s",
               PyObject_REPR(w)); 
         break;

      ÕâÊÇ´æÔÚfooÍâ²ãframeµÄµÄlocalÀï°É£¿µ«ÊÇÍâ²ãbyte codeÀïxûÓÐÔÚco_varnamesÀïÃ棬ÄÇôËü¾ÍÓ¦¸ÃÔÚglobalÀï°É£¿
      fooÀïÃæÓÖÈçºÎ´ÓÍâ²ã´«½øÀ´µÄglobal±íÀï²éµ½xµÄÖµÄØ£¿ÎÒÔõôҲÕÒ²»µ½fooÍâÃ潫x¸³Öµµ½global±íµÄ²¿·Ö£¬Çó½ÌÁË£¡
      _______________________________________________
      python-chinese 
      Post: send python-chinese在lists.python.cn
      Subscribe: send subscribe to python-chinese-request在lists.python.cn 
      Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
      Detail Info: http://python.cn/mailman/listinfo/python-chinese 



    -- 
    »¶Ó­·ÃÎÊ£º
    http://blog.csdn.net/ccat

    ÁõöÎ
    March.Liu



----------------------------------------------------------------------------


    _______________________________________________
    python-chinese
    Post: send python-chinese在lists.python.cn
    Subscribe: send subscribe to python-chinese-request在lists.python.cn
    Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
    Detail Info: http://python.cn/mailman/listinfo/python-chinese


------------------------------------------------------------------------------


  _______________________________________________
  python-chinese
  Post: send python-chinese在lists.python.cn
  Subscribe: send subscribe to python-chinese-request在lists.python.cn
  Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
  Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061129/eca8dae9/attachment-0001.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年11月29日 星期三 15:53

Robert Chen search.pythoner在gmail.com
星期三 十一月 29 15:53:03 HKT 2006

ºÇºÇ£¬Ô­ÒòºÜ¼òµ¥£¬ÔÚfooÖ®ÍâµÄframeÖУ¬localºÍglobalÊÇͬһ¸ödict¡£
x = 1
def foo():
    print '================= local %d =================\n' % id(locals()),
locals()
    print '================= global %d =================\n' % id(globals()),
globals()
    y = x+1
    print x
    print y

print '================= local %d =================\n' % id(locals()),
locals()
print '================= global %d =================\n' % id(globals()),
globals()
foo()
print x

´ÓÊä³öµÄ½á¹ûÖпÉÒÔ¿´µ½ÕâÒ»µã£¬ËùÒÔfooÖ®ÍâÏòlocalÖÐÉèÖÃÖµ¾ÍÊÇÏòglobalÖÐÉèÖÃÖµ¡£

On 11/29/06, libing <imlibing在163.com> wrote:
>
>    3           0 LOAD_GLOBAL              0 (x)
> ÕâÌõÊÇfoo´ÓglobalÀï²éxµÄ£¬globalÓÖÊÇ´ÓfooÍâÃæ´«½øÀ´µÄ£¬µ«ÊÇÎÊÌâÊÇÔÚfooÍâÃæûÓп´µ½ÍùglobalÉèxÖµµÄ´úÂ룬ÓеÄÖ»ÊÇ
>               3 STORE_NAME               0 (x)
> ÕâÌõ£¬ÕâÊÇÍùfooÍâÃæµÄlocal²åÊý¾ÝµÄ
>
> ----- Original Message -----
> *From:* ÁõöÎ <march.liu在gmail.com>
> *To:* python-chinese在lists.python.cn
> *Sent:* Wednesday, November 29, 2006 11:03 AM
> *Subject:* Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡
>
> Ó¦¸ÃÊÇÕâÌõ
>   3           0 LOAD_GLOBAL              0 (x)
> ÎÒ²ÂÏëÊǽâÊÍÆ÷±àÒëfooµÄʱºò£¬ÔÚfooÄÚ²¿ÕÒ²»µ½xµÄ¸³Öµ£¬¾ÍÖ±½ÓÔÚ×îÇ°Ãæ²åÈëÁËÕâ¸öÖ¸Áî¡£
>
> 2006/11/29, libing <imlibing在163.com>:
> >
> > hello,´ó¼ÒºÃ£¬Ð¡µÜ×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡
> >
> > ¶ÔÒ»¶Î´úÂ룺
> > x = 1
> > def foo():
> > y = x+1
> > print x
> > print y
> > foo()
> > print x
> >
> > ÎÒ´òÓ¡³öËüµÄcode object ½á¹¹³öÀ´·ÖÎö£º
> > £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
> > co_names : ('x', 'foo')
> > co_varnames : ()
> > co_freevars : ()
> > co_cellvars : ()
> >   1           0 LOAD_CONST               0 (1)
> >               3 STORE_NAME               0 (x)
> >
> >   2           6 LOAD_CONST               1 (> > 010167B8, file "string", line 2>)
> >
> > nest code object begin <<<<<
> > co_names : ('x',)
> > co_varnames : ('y',)
> > co_freevars : ()
> > co_cellvars : ()
> >   3           0 LOAD_GLOBAL              0 (x)
> >               3 LOAD_CONST               1 (1)
> >               6 BINARY_ADD
> >               7 STORE_FAST               0 (y)
> >
> >   4          10 LOAD_GLOBAL              0 (x)
> >              13 PRINT_ITEM
> >              14 PRINT_NEWLINE
> >
> >   5          15 LOAD_FAST                0 (y)
> >              18 PRINT_ITEM
> >              19 PRINT_NEWLINE
> >              20 LOAD_CONST               0 (None)
> >              23 RETURN_VALUE
> > nest code object end >>>>>
> >
> >               9 MAKE_FUNCTION            0
> >              12 STORE_NAME               1 (foo)
> >
> >   6          15 LOAD_NAME                1 (foo)
> >              18 CALL_FUNCTION            0
> >              21 POP_TOP
> >
> >   7          22 LOAD_NAME                0 (x)
> >              25 PRINT_ITEM
> >              26 PRINT_NEWLINE
> >              27 LOAD_CONST               2 (None)
> >              30 RETURN_VALUE
> > £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
> >
> > ÔÚÍâ²ã´æxÖµµÄʱºòµÄbyte codeÊÇ              3 STORE_NAME               0 (x)
> > ÔÚceval.cÔ´ÂëÀïÕâ¶Î¶ÔÓ¦µÄÊÇ
> >   case STORE_NAME:
> >    w = GETITEM(names, oparg);
> >    v = POP();
> >    if ((x = f->f_locals) != NULL) {
> >     if (PyDict_CheckExact(x))
> >      err = PyDict_SetItem(x, w, v);
> >     else
> >      err = PyObject_SetItem(x, w, v);
> >     Py_DECREF(v);
> >     if (err == 0) continue;
> >     break;
> >    }
> >    PyErr_Format(PyExc_SystemError,
> >          "no locals found when storing %s",
> >          PyObject_REPR(w));
> >    break;
> >
> > ÕâÊÇ´æÔÚfooÍâ²ãframeµÄµÄlocalÀï°É£¿µ«ÊÇÍâ²ãbyte codeÀïxûÓÐÔÚco_varnamesÀïÃ棬ÄÇôËü¾ÍÓ¦¸ÃÔÚglobalÀï°É£¿
> > fooÀïÃæÓÖÈçºÎ´ÓÍâ²ã´«½øÀ´µÄglobal±íÀï²éµ½xµÄÖµÄØ£¿ÎÒÔõôҲÕÒ²»µ½fooÍâÃ潫x¸³Öµµ½global±íµÄ²¿·Ö£¬Çó½ÌÁË£¡
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
>
>
> --
> »¶Ó­·ÃÎÊ£º
> http://blog.csdn.net/ccat
>
> ÁõöÎ
> March.Liu
>
> ------------------------------
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>



-- 
Robert
PythonÔ´ÂëÆÊÎö¡ª¡ªhttp://blog.donews.com/lemur/
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061129/f5d6bb9f/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年11月29日 星期三 15:54

刘鑫 march.liu在gmail.com
星期三 十一月 29 15:54:51 HKT 2006

Ê̡ܽ£

ÔÚ06-11-29£¬Robert Chen <search.pythoner在gmail.com> дµÀ£º
>
> ºÇºÇ£¬Ô­ÒòºÜ¼òµ¥£¬ÔÚfooÖ®ÍâµÄframeÖУ¬localºÍglobalÊÇͬһ¸ödict¡£
> x = 1
> def foo():
>     print '================= local %d =================\n' % id(locals()),
> locals()
>     print '================= global %d =================\n' %
> id(globals()), globals()
>     y = x+1
>     print x
>     print y
>
> print '================= local %d =================\n' % id(locals()),
> locals()
> print '================= global %d =================\n' % id(globals()),
> globals()
> foo()
> print x
>
> ´ÓÊä³öµÄ½á¹ûÖпÉÒÔ¿´µ½ÕâÒ»µã£¬ËùÒÔfooÖ®ÍâÏòlocalÖÐÉèÖÃÖµ¾ÍÊÇÏòglobalÖÐÉèÖÃÖµ¡£
>
> On 11/29/06, libing <imlibing在163.com> wrote:
> >
> >    3           0 LOAD_GLOBAL              0 (x)
> > ÕâÌõÊÇfoo´ÓglobalÀï²éxµÄ£¬globalÓÖÊÇ´ÓfooÍâÃæ´«½øÀ´µÄ£¬µ«ÊÇÎÊÌâÊÇÔÚfooÍâÃæûÓп´µ½ÍùglobalÉèxÖµµÄ´úÂ룬ÓеÄÖ»ÊÇ
> >               3 STORE_NAME               0 (x)
> > ÕâÌõ£¬ÕâÊÇÍùfooÍâÃæµÄlocal²åÊý¾ÝµÄ
> >
> > ----- Original Message -----
> > *From:* ÁõöÎ <march.liu在gmail.com>
> > *To:* python-chinese在lists.python.cn
> > *Sent:* Wednesday, November 29, 2006 11:03 AM
> > *Subject:* Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡
> >
> > Ó¦¸ÃÊÇÕâÌõ
> >   3           0 LOAD_GLOBAL              0 (x)
> > ÎÒ²ÂÏëÊǽâÊÍÆ÷±àÒëfooµÄʱºò£¬ÔÚfooÄÚ²¿ÕÒ²»µ½xµÄ¸³Öµ£¬¾ÍÖ±½ÓÔÚ×îÇ°Ãæ²åÈëÁËÕâ¸öÖ¸Áî¡£
> >
> > 2006/11/29, libing <imlibing在163.com>:
> > >
> > > hello,´ó¼ÒºÃ£¬Ð¡µÜ×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡
> > >
> > > ¶ÔÒ»¶Î´úÂ룺
> > > x = 1
> > > def foo():
> > > y = x+1
> > > print x
> > > print y
> > > foo()
> > > print x
> > >
> > > ÎÒ´òÓ¡³öËüµÄcode object ½á¹¹³öÀ´·ÖÎö£º
> > > £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
> > > co_names : ('x', 'foo')
> > > co_varnames : ()
> > > co_freevars : ()
> > > co_cellvars : ()
> > >   1           0 LOAD_CONST               0 (1)
> > >               3 STORE_NAME               0 (x)
> > >
> > >   2           6 LOAD_CONST               1 (> > > 010167B8, file "string", line 2>)
> > >
> > > nest code object begin <<<<<
> > > co_names : ('x',)
> > > co_varnames : ('y',)
> > > co_freevars : ()
> > > co_cellvars : ()
> > >   3           0 LOAD_GLOBAL              0 (x)
> > >               3 LOAD_CONST               1 (1)
> > >               6 BINARY_ADD
> > >               7 STORE_FAST               0 (y)
> > >
> > >   4          10 LOAD_GLOBAL              0 (x)
> > >              13 PRINT_ITEM
> > >              14 PRINT_NEWLINE
> > >
> > >   5          15 LOAD_FAST                0 (y)
> > >              18 PRINT_ITEM
> > >              19 PRINT_NEWLINE
> > >              20 LOAD_CONST               0 (None)
> > >              23 RETURN_VALUE
> > > nest code object end >>>>>
> > >
> > >               9 MAKE_FUNCTION            0
> > >              12 STORE_NAME               1 (foo)
> > >
> > >   6          15 LOAD_NAME                1 (foo)
> > >              18 CALL_FUNCTION            0
> > >              21 POP_TOP
> > >
> > >   7          22 LOAD_NAME                0 (x)
> > >              25 PRINT_ITEM
> > >              26 PRINT_NEWLINE
> > >              27 LOAD_CONST               2 (None)
> > >              30 RETURN_VALUE
> > > £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
> > >
> > > ÔÚÍâ²ã´æxÖµµÄʱºòµÄbyte codeÊÇ              3 STORE_NAME               0 (x)
> > > ÔÚceval.cÔ´ÂëÀïÕâ¶Î¶ÔÓ¦µÄÊÇ
> > >   case STORE_NAME:
> > >    w = GETITEM(names, oparg);
> > >    v = POP();
> > >    if ((x = f->f_locals) != NULL) {
> > >     if (PyDict_CheckExact(x))
> > >      err = PyDict_SetItem(x, w, v);
> > >     else
> > >      err = PyObject_SetItem(x, w, v);
> > >     Py_DECREF(v);
> > >     if (err == 0) continue;
> > >     break;
> > >    }
> > >    PyErr_Format(PyExc_SystemError,
> > >          "no locals found when storing %s",
> > >          PyObject_REPR(w));
> > >    break;
> > >
> > > ÕâÊÇ´æÔÚfooÍâ²ãframeµÄµÄlocalÀï°É£¿µ«ÊÇÍâ²ãbyte
> > > codeÀïxûÓÐÔÚco_varnamesÀïÃ棬ÄÇôËü¾ÍÓ¦¸ÃÔÚglobalÀï°É£¿
> > > fooÀïÃæÓÖÈçºÎ´ÓÍâ²ã´«½øÀ´µÄglobal±íÀï²éµ½xµÄÖµÄØ£¿ÎÒÔõôҲÕÒ²»µ½fooÍâÃ潫x¸³Öµµ½global±íµÄ²¿·Ö£¬Çó½ÌÁË£¡
> > > _______________________________________________
> > > python-chinese
> > > Post: send python-chinese在lists.python.cn
> > > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > > Unsubscribe: send unsubscribe to
> > > python-chinese-request在lists.python.cn
> > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> >
> >
> >
> > --
> > »¶Ó­·ÃÎÊ£º
> > http://blog.csdn.net/ccat
> >
> > ÁõöÎ
> > March.Liu
> >
> > ------------------------------
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
>
>
>
> --
> Robert
> PythonÔ´ÂëÆÊÎö¡ª¡ªhttp://blog.donews.com/lemur/
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>



-- 
»¶Ó­·ÃÎÊ£º
http://blog.csdn.net/ccat

ÁõöÎ
March.Liu
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061129/571447ad/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年11月29日 星期三 16:11

libing imlibing在163.com
星期三 十一月 29 16:11:40 HKT 2006

ÖÕÓڵȵ½´óÏÀµÄ»ØÐÅÁË£¬´óÏÀµÄcpythonÔ´ÂëÆÊÎöϵÁÐÔõô¾ÍÍ£ÁËÄØ?ÎÒ»¹µÈ×ŰݶÁÄØ¡£

ÄÇô»¹ÓиöÎÊÌ⣺һ¶ÎÄÚ²ã´úÂëÀïÃæµÄlocalµÄ±äÁ¿µÄ´æ´¢¶àÓÃSTORE_FASTºÍLOAD_FASTÖ±½Ó´æÔÚframeÉÏ£¬ÎªÊ²Ã´»¹Òª·ÑʼӸölocal²ÎÊý´«½øÀ´Ò»¸ö±íÄØ£¿
ʲôÇé¿öÏ»áרÃÅ´«½øÀ´Ò»¸ölocal±í£¿
  ----- Original Message ----- 
  From: Robert Chen 
  To: python-chinese在lists.python.cn 
  Sent: Wednesday, November 29, 2006 3:53 PM
  Subject: Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡


  ºÇºÇ£¬Ô­ÒòºÜ¼òµ¥£¬ÔÚfooÖ®ÍâµÄframeÖУ¬localºÍglobalÊÇͬһ¸ödict¡£
  x = 1
  def foo():
      print '================= local %d =================\n' % id(locals()), locals()
      print '================= global %d =================\n' % id(globals()), globals() 
      y = x+1
      print x
      print y

  print '================= local %d =================\n' % id(locals()), locals()
  print '================= global %d =================\n' % id(globals()), globals()
  foo()
  print x

  ´ÓÊä³öµÄ½á¹ûÖпÉÒÔ¿´µ½ÕâÒ»µã£¬ËùÒÔfooÖ®ÍâÏòlocalÖÐÉèÖÃÖµ¾ÍÊÇÏòglobalÖÐÉèÖÃÖµ¡£


  On 11/29/06, libing <imlibing在163.com> wrote: 
      3           0 LOAD_GLOBAL              0 (x)
    ÕâÌõÊÇfoo´ÓglobalÀï²éxµÄ£¬globalÓÖÊÇ´ÓfooÍâÃæ´«½øÀ´µÄ£¬µ«ÊÇÎÊÌâÊÇÔÚfooÍâÃæûÓп´µ½ÍùglobalÉèxÖµµÄ´úÂ룬ÓеÄÖ»ÊÇ
                  3 STORE_NAME               0 (x)
    ÕâÌõ£¬ÕâÊÇÍùfooÍâÃæµÄlocal²åÊý¾ÝµÄ
      ----- Original Message ----- 
      From: ÁõöÎ 
      To: python-chinese在lists.python.cn 
      Sent: Wednesday, November 29, 2006 11:03 AM
      Subject: Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡


      Ó¦¸ÃÊÇÕâÌõ
        3           0 LOAD_GLOBAL              0 (x)
      ÎÒ²ÂÏëÊǽâÊÍÆ÷±àÒëfooµÄʱºò£¬ÔÚfooÄÚ²¿ÕÒ²»µ½xµÄ¸³Öµ£¬¾ÍÖ±½ÓÔÚ×îÇ°Ãæ²åÈëÁËÕâ¸öÖ¸Áî¡£


      2006/11/29, libing <imlibing在163.com>: 
        hello,´ó¼ÒºÃ£¬Ð¡µÜ×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡

        ¶ÔÒ»¶Î´úÂ룺
        x = 1
        def foo():
        y = x+1 
        print x
        print y
        foo()
        print x

        ÎÒ´òÓ¡³öËüµÄcode object ½á¹¹³öÀ´·ÖÎö£º
        £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
        co_names : ('x', 'foo')
        co_varnames : ()
        co_freevars : ()
        co_cellvars : ()
          1           0 LOAD_CONST               0 (1)
                      3 STORE_NAME               0 (x)

          2           6 LOAD_CONST               1 ()

        nest code object begin <<<<<
        co_names : ('x',)
        co_varnames : ('y',)
        co_freevars : ()
        co_cellvars : ()
          3           0 LOAD_GLOBAL              0 (x)
                      3 LOAD_CONST               1 (1) 
                      6 BINARY_ADD
                      7 STORE_FAST               0 (y)

          4          10 LOAD_GLOBAL              0 (x)
                     13 PRINT_ITEM
                     14 PRINT_NEWLINE

          5          15 LOAD_FAST                0 (y) 
                     18 PRINT_ITEM
                     19 PRINT_NEWLINE
                     20 LOAD_CONST               0 (None)
                     23 RETURN_VALUE
        nest code object end >>>>>

                      9 MAKE_FUNCTION            0 
                     12 STORE_NAME               1 (foo)

          6          15 LOAD_NAME                1 (foo)
                     18 CALL_FUNCTION            0
                     21 POP_TOP

          7          22 LOAD_NAME                0 (x) 
                     25 PRINT_ITEM
                     26 PRINT_NEWLINE
                     27 LOAD_CONST               2 (None)
                     30 RETURN_VALUE
        £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½

        ÔÚÍâ²ã´æxÖµµÄʱºòµÄbyte codeÊÇ              3 STORE_NAME               0 (x) 
        ÔÚceval.cÔ´ÂëÀïÕâ¶Î¶ÔÓ¦µÄÊÇ
          case STORE_NAME:
           w = GETITEM(names, oparg);
           v = POP();
           if ((x = f->f_locals) != NULL) {
            if (PyDict_CheckExact(x))
             err = PyDict_SetItem(x, w, v);
            else
             err = PyObject_SetItem(x, w, v);
            Py_DECREF(v);
            if (err == 0) continue;
            break;
           }
           PyErr_Format(PyExc_SystemError,
                 "no locals found when storing %s",
                 PyObject_REPR(w)); 
           break;

        ÕâÊÇ´æÔÚfooÍâ²ãframeµÄµÄlocalÀï°É£¿µ«ÊÇÍâ²ãbyte codeÀïxûÓÐÔÚco_varnamesÀïÃ棬ÄÇôËü¾ÍÓ¦¸ÃÔÚglobalÀï°É£¿
        fooÀïÃæÓÖÈçºÎ´ÓÍâ²ã´«½øÀ´µÄglobal±íÀï²éµ½xµÄÖµÄØ£¿ÎÒÔõôҲÕÒ²»µ½fooÍâÃ潫x¸³Öµµ½global±íµÄ²¿·Ö£¬Çó½ÌÁË£¡
        _______________________________________________
        python-chinese 
        Post: send python-chinese在lists.python.cn
        Subscribe: send subscribe to python-chinese-request在lists.python.cn 
        Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
        Detail Info: http://python.cn/mailman/listinfo/python-chinese 



      -- 
      »¶Ó­·ÃÎÊ£º
      http://blog.csdn.net/ccat

      ÁõöÎ
      March.Liu 



--------------------------------------------------------------------------


      _______________________________________________
      python-chinese
      Post: send python-chinese在lists.python.cn
      Subscribe: send subscribe to python-chinese-request在lists.python.cn
      Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
      Detail Info: http://python.cn/mailman/listinfo/python-chinese


    _______________________________________________
    python-chinese
    Post: send python-chinese在lists.python.cn 
    Subscribe: send subscribe to python-chinese-request在lists.python.cn
    Unsubscribe: send unsubscribe to   python-chinese-request在lists.python.cn
    Detail Info: http://python.cn/mailman/listinfo/python-chinese




  -- 
  Robert
  PythonÔ´ÂëÆÊÎö¡ª¡ªhttp://blog.donews.com/lemur/ 


------------------------------------------------------------------------------


  _______________________________________________
  python-chinese
  Post: send python-chinese在lists.python.cn
  Subscribe: send subscribe to python-chinese-request在lists.python.cn
  Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
  Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061129/7b874617/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年11月29日 星期三 16:41

Robert Chen search.pythoner在gmail.com
星期三 十一月 29 16:41:51 HKT 2006

ºÇºÇÐǪ̈¿ÍÆøÁË£¬Ô´ÂëÆÊÎöϵÁÐÍ£ÁËÏÂÀ´Ô­ÒòÓж෽Ã棬ºÇºÇ²»¹ýÖ÷Òª»¹ÊÇ×Ô¼º±È½ÏÀÁ£¬¹ý¶Îʱ¼ä×¼±¸ÖØпªÊ¼·¢²¼£¬½«Ä¿Ç°ÎªÖ¹ËùÓеķÖÎö½á¹û¹²Ïí³öÀ´¡£

²»¹ýºÜ³¤Ò»¶Îʱ¼äûÓп´PythonµÄÔ´ÂëÁË£¬ÒÔÇ°·ÖÎöµÄ½á¹ûÒ²ÍüµÃ²î²»¶àÁË£¬ÄãµÄÎÊÌâÎÒ»¹Õæ²»ºÃ»Ø´ð£¬±§Ç¸¡£²»¹ý»¹ºÃµ±Ê±¼Ç¼ÓÐÎĵµ£¬ÕùÈ¡¹ý¶Îʱ¼ä¾Í°ÑËüÃÇshare³öÀ´£¬¾ÍÏñÏÖÔÚµÄDjango
BookÒ»ÑùºÇºÇ¡£µ½Ê±ºòÏ£ÍûºÍÐǪ̈¶à¶àÌÖÂÛ £º£©

On 11/29/06, libing <imlibing在163.com> wrote:
>
>  ÖÕÓڵȵ½´óÏÀµÄ»ØÐÅÁË£¬´óÏÀµÄcpythonÔ´ÂëÆÊÎöϵÁÐÔõô¾ÍÍ£ÁËÄØ?ÎÒ»¹µÈ×ŰݶÁÄØ¡£
>
>
> ÄÇô»¹ÓиöÎÊÌ⣺һ¶ÎÄÚ²ã´úÂëÀïÃæµÄlocalµÄ±äÁ¿µÄ´æ´¢¶àÓÃSTORE_FASTºÍLOAD_FASTÖ±½Ó´æÔÚframeÉÏ£¬ÎªÊ²Ã´»¹Òª·ÑʼӸölocal²ÎÊý´«½øÀ´Ò»¸ö±íÄØ£¿
> ʲôÇé¿öÏ»áרÃÅ´«½øÀ´Ò»¸ölocal±í£¿
>
> ----- Original Message -----
> *From:* Robert Chen <search.pythoner在gmail.com>
> *To:* python-chinese在lists.python.cn
> *Sent:* Wednesday, November 29, 2006 3:53 PM
> *Subject:* Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡
>
> ºÇºÇ£¬Ô­ÒòºÜ¼òµ¥£¬ÔÚfooÖ®ÍâµÄframeÖУ¬localºÍglobalÊÇͬһ¸ödict¡£
> x = 1
> def foo():
>     print '================= local %d =================\n' % id(locals()),
> locals()
>     print '================= global %d =================\n' %
> id(globals()), globals()
>     y = x+1
>     print x
>     print y
>
> print '================= local %d =================\n' % id(locals()),
> locals()
> print '================= global %d =================\n' % id(globals()),
> globals()
> foo()
> print x
>
> ´ÓÊä³öµÄ½á¹ûÖпÉÒÔ¿´µ½ÕâÒ»µã£¬ËùÒÔfooÖ®ÍâÏòlocalÖÐÉèÖÃÖµ¾ÍÊÇÏòglobalÖÐÉèÖÃÖµ¡£
>
> On 11/29/06, libing <imlibing在163.com> wrote:
> >
> >    3           0 LOAD_GLOBAL              0 (x)
> > ÕâÌõÊÇfoo´ÓglobalÀï²éxµÄ£¬globalÓÖÊÇ´ÓfooÍâÃæ´«½øÀ´µÄ£¬µ«ÊÇÎÊÌâÊÇÔÚfooÍâÃæûÓп´µ½ÍùglobalÉèxÖµµÄ´úÂ룬ÓеÄÖ»ÊÇ
> >               3 STORE_NAME               0 (x)
> > ÕâÌõ£¬ÕâÊÇÍùfooÍâÃæµÄlocal²åÊý¾ÝµÄ
> >
> >  ----- Original Message -----
> > *From:* ÁõöÎ <march.liu在gmail.com>
> > *To:* python-chinese在lists.python.cn
> > *Sent:* Wednesday, November 29, 2006 11:03 AM
> > *Subject:* Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡
> >
> > Ó¦¸ÃÊÇÕâÌõ
> >   3           0 LOAD_GLOBAL              0 (x)
> > ÎÒ²ÂÏëÊǽâÊÍÆ÷±àÒëfooµÄʱºò£¬ÔÚfooÄÚ²¿ÕÒ²»µ½xµÄ¸³Öµ£¬¾ÍÖ±½ÓÔÚ×îÇ°Ãæ²åÈëÁËÕâ¸öÖ¸Áî¡£
> >
> > 2006/11/29, libing <imlibing在163.com>:
> > >
> > > hello,´ó¼ÒºÃ£¬Ð¡µÜ×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡
> > >
> > > ¶ÔÒ»¶Î´úÂ룺
> > > x = 1
> > > def foo():
> > > y = x+1
> > > print x
> > > print y
> > > foo()
> > > print x
> > >
> > > ÎÒ´òÓ¡³öËüµÄcode object ½á¹¹³öÀ´·ÖÎö£º
> > > £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
> > > co_names : ('x', 'foo')
> > > co_varnames : ()
> > > co_freevars : ()
> > > co_cellvars : ()
> > >   1           0 LOAD_CONST               0 (1)
> > >               3 STORE_NAME               0 (x)
> > >
> > >   2           6 LOAD_CONST               1 (> > > 010167B8, file "string", line 2>)
> > >
> > > nest code object begin <<<<<
> > > co_names : ('x',)
> > > co_varnames : ('y',)
> > > co_freevars : ()
> > > co_cellvars : ()
> > >   3           0 LOAD_GLOBAL              0 (x)
> > >               3 LOAD_CONST               1 (1)
> > >               6 BINARY_ADD
> > >               7 STORE_FAST               0 (y)
> > >
> > >   4          10 LOAD_GLOBAL              0 (x)
> > >              13 PRINT_ITEM
> > >              14 PRINT_NEWLINE
> > >
> > >   5          15 LOAD_FAST                0 (y)
> > >              18 PRINT_ITEM
> > >              19 PRINT_NEWLINE
> > >              20 LOAD_CONST               0 (None)
> > >              23 RETURN_VALUE
> > > nest code object end >>>>>
> > >
> > >               9 MAKE_FUNCTION            0
> > >              12 STORE_NAME               1 (foo)
> > >
> > >   6          15 LOAD_NAME                1 (foo)
> > >              18 CALL_FUNCTION            0
> > >              21 POP_TOP
> > >
> > >   7          22 LOAD_NAME                0 (x)
> > >              25 PRINT_ITEM
> > >              26 PRINT_NEWLINE
> > >              27 LOAD_CONST               2 (None)
> > >              30 RETURN_VALUE
> > > £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
> > >
> > > ÔÚÍâ²ã´æxÖµµÄʱºòµÄbyte codeÊÇ              3 STORE_NAME               0 (x)
> > > ÔÚceval.cÔ´ÂëÀïÕâ¶Î¶ÔÓ¦µÄÊÇ
> > >   case STORE_NAME:
> > >    w = GETITEM(names, oparg);
> > >    v = POP();
> > >    if ((x = f->f_locals) != NULL) {
> > >     if (PyDict_CheckExact(x))
> > >      err = PyDict_SetItem(x, w, v);
> > >     else
> > >      err = PyObject_SetItem(x, w, v);
> > >     Py_DECREF(v);
> > >     if (err == 0) continue;
> > >     break;
> > >    }
> > >    PyErr_Format(PyExc_SystemError,
> > >          "no locals found when storing %s",
> > >          PyObject_REPR(w));
> > >    break;
> > >
> > > ÕâÊÇ´æÔÚfooÍâ²ãframeµÄµÄlocalÀï°É£¿µ«ÊÇÍâ²ãbyte
> > > codeÀïxûÓÐÔÚco_varnamesÀïÃ棬ÄÇôËü¾ÍÓ¦¸ÃÔÚglobalÀï°É£¿
> > > fooÀïÃæÓÖÈçºÎ´ÓÍâ²ã´«½øÀ´µÄglobal±íÀï²éµ½xµÄÖµÄØ£¿ÎÒÔõôҲÕÒ²»µ½fooÍâÃ潫x¸³Öµµ½global±íµÄ²¿·Ö£¬Çó½ÌÁË£¡
> > > _______________________________________________
> > > python-chinese
> > > Post: send python-chinese在lists.python.cn
> > > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > > Unsubscribe: send unsubscribe to
> > > python-chinese-request在lists.python.cn
> > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> >
> >
> >
> > --
> > »¶Ó­·ÃÎÊ£º
> > http://blog.csdn.net/ccat
> >
> > ÁõöÎ
> > March.Liu
> >
> > ------------------------------
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
>
>
>
> --
> Robert
> PythonÔ´ÂëÆÊÎö¡ª¡ªhttp://blog.donews.com/lemur/
>
> ------------------------------
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>



-- 
Robert
PythonÔ´ÂëÆÊÎö¡ª¡ªhttp://blog.donews.com/lemur/
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061129/4fbcda53/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年11月29日 星期三 17:04

libing imlibing在163.com
星期三 十一月 29 17:04:11 HKT 2006

ÆÚ´ý£¬ÆÚ´ý
  ----- Original Message ----- 
  From: Robert Chen 
  To: python-chinese在lists.python.cn 
  Sent: Wednesday, November 29, 2006 4:41 PM
  Subject: Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡


  ºÇºÇÐǪ̈¿ÍÆøÁË£¬Ô´ÂëÆÊÎöϵÁÐÍ£ÁËÏÂÀ´Ô­ÒòÓж෽Ã棬ºÇºÇ²»¹ýÖ÷Òª»¹ÊÇ×Ô¼º±È½ÏÀÁ£¬¹ý¶Îʱ¼ä×¼±¸ÖØпªÊ¼·¢²¼£¬½«Ä¿Ç°ÎªÖ¹ËùÓеķÖÎö½á¹û¹²Ïí³öÀ´¡£

  ²»¹ýºÜ³¤Ò»¶Îʱ¼äûÓп´PythonµÄÔ´ÂëÁË£¬ÒÔÇ°·ÖÎöµÄ½á¹ûÒ²ÍüµÃ²î²»¶àÁË£¬ÄãµÄÎÊÌâÎÒ»¹Õæ²»ºÃ»Ø´ð£¬±§Ç¸¡£²»¹ý»¹ºÃµ±Ê±¼Ç¼ÓÐÎĵµ£¬ÕùÈ¡¹ý¶Îʱ¼ä¾Í°ÑËüÃÇshare³öÀ´£¬¾ÍÏñÏÖÔÚµÄDjango BookÒ»ÑùºÇºÇ¡£µ½Ê±ºòÏ£ÍûºÍÐǪ̈¶à¶àÌÖÂÛ £º£©


  On 11/29/06, libing <imlibing在163.com> wrote:
    ÖÕÓڵȵ½´óÏÀµÄ»ØÐÅÁË£¬´óÏÀµÄcpythonÔ´ÂëÆÊÎöϵÁÐÔõô¾ÍÍ£ÁËÄØ?ÎÒ»¹µÈ×ŰݶÁÄØ¡£

    ÄÇô»¹ÓиöÎÊÌ⣺һ¶ÎÄÚ²ã´úÂëÀïÃæµÄlocalµÄ±äÁ¿µÄ´æ´¢¶àÓÃSTORE_FASTºÍLOAD_FASTÖ±½Ó´æÔÚframeÉÏ£¬ÎªÊ²Ã´»¹Òª·ÑʼӸölocal²ÎÊý´«½øÀ´Ò»¸ö±íÄØ£¿
    ʲôÇé¿öÏ»áרÃÅ´«½øÀ´Ò»¸ölocal±í£¿
      ----- Original Message ----- 
      From: Robert Chen 
      To: python-chinese在lists.python.cn 
      Sent: Wednesday, November 29, 2006 3:53 PM
      Subject: Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡


      ºÇºÇ£¬Ô­ÒòºÜ¼òµ¥£¬ÔÚfooÖ®ÍâµÄframeÖУ¬localºÍglobalÊÇͬһ¸ödict¡£
      x = 1
      def foo():
          print '================= local %d =================\n' % id(locals()), locals()
          print '================= global %d =================\n' % id(globals()), globals() 
          y = x+1
          print x
          print y

      print '================= local %d =================\n' % id(locals()), locals()
      print '================= global %d =================\n' % id(globals()), globals()
      foo()
      print x

      ´ÓÊä³öµÄ½á¹ûÖпÉÒÔ¿´µ½ÕâÒ»µã£¬ËùÒÔfooÖ®ÍâÏòlocalÖÐÉèÖÃÖµ¾ÍÊÇÏòglobalÖÐÉèÖÃÖµ¡£


      On 11/29/06, libing <imlibing在163.com> wrote: 
          3           0 LOAD_GLOBAL              0 (x)
        ÕâÌõÊÇfoo´ÓglobalÀï²éxµÄ£¬globalÓÖÊÇ´ÓfooÍâÃæ´«½øÀ´µÄ£¬µ«ÊÇÎÊÌâÊÇÔÚfooÍâÃæûÓп´µ½ÍùglobalÉèxÖµµÄ´úÂ룬ÓеÄÖ»ÊÇ
                      3 STORE_NAME               0 (x)
        ÕâÌõ£¬ÕâÊÇÍùfooÍâÃæµÄlocal²åÊý¾ÝµÄ
          ----- Original Message ----- 
          From: ÁõöÎ 
          To: python-chinese在lists.python.cn 
          Sent: Wednesday, November 29, 2006 11:03 AM
          Subject: Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡


          Ó¦¸ÃÊÇÕâÌõ
            3           0 LOAD_GLOBAL              0 (x)
          ÎÒ²ÂÏëÊǽâÊÍÆ÷±àÒëfooµÄʱºò£¬ÔÚfooÄÚ²¿ÕÒ²»µ½xµÄ¸³Öµ£¬¾ÍÖ±½ÓÔÚ×îÇ°Ãæ²åÈëÁËÕâ¸öÖ¸Áî¡£


          2006/11/29, libing <imlibing在163.com>: 
            hello,´ó¼ÒºÃ£¬Ð¡µÜ×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡

            ¶ÔÒ»¶Î´úÂ룺
            x = 1
            def foo():
            y = x+1 
            print x
            print y
            foo()
            print x

            ÎÒ´òÓ¡³öËüµÄcode object ½á¹¹³öÀ´·ÖÎö£º
            £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
            co_names : ('x', 'foo')
            co_varnames : ()
            co_freevars : ()
            co_cellvars : ()
              1           0 LOAD_CONST               0 (1)
                          3 STORE_NAME               0 (x)

              2           6 LOAD_CONST               1 ()

            nest code object begin <<<<<
            co_names : ('x',)
            co_varnames : ('y',)
            co_freevars : ()
            co_cellvars : ()
              3           0 LOAD_GLOBAL              0 (x)
                          3 LOAD_CONST               1 (1) 
                          6 BINARY_ADD
                          7 STORE_FAST               0 (y)

              4          10 LOAD_GLOBAL              0 (x)
                         13 PRINT_ITEM
                         14 PRINT_NEWLINE

              5          15 LOAD_FAST                0 (y) 
                         18 PRINT_ITEM
                         19 PRINT_NEWLINE
                         20 LOAD_CONST               0 (None)
                         23 RETURN_VALUE
            nest code object end >>>>>

                          9 MAKE_FUNCTION            0 
                         12 STORE_NAME               1 (foo)

              6          15 LOAD_NAME                1 (foo)
                         18 CALL_FUNCTION            0
                         21 POP_TOP

              7          22 LOAD_NAME                0 (x) 
                         25 PRINT_ITEM
                         26 PRINT_NEWLINE
                         27 LOAD_CONST               2 (None)
                         30 RETURN_VALUE
            £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½

            ÔÚÍâ²ã´æxÖµµÄʱºòµÄbyte codeÊÇ              3 STORE_NAME               0 (x) 
            ÔÚceval.cÔ´ÂëÀïÕâ¶Î¶ÔÓ¦µÄÊÇ
              case STORE_NAME:
               w = GETITEM(names, oparg);
               v = POP();
               if ((x = f->f_locals) != NULL) {
                if (PyDict_CheckExact(x))
                 err = PyDict_SetItem(x, w, v);
                else
                 err = PyObject_SetItem(x, w, v);
                Py_DECREF(v);
                if (err == 0) continue;
                break;
               }
               PyErr_Format(PyExc_SystemError,
                     "no locals found when storing %s",
                     PyObject_REPR(w)); 
               break;

            ÕâÊÇ´æÔÚfooÍâ²ãframeµÄµÄlocalÀï°É£¿µ«ÊÇÍâ²ãbyte codeÀïxûÓÐÔÚco_varnamesÀïÃ棬ÄÇôËü¾ÍÓ¦¸ÃÔÚglobalÀï°É£¿
            fooÀïÃæÓÖÈçºÎ´ÓÍâ²ã´«½øÀ´µÄglobal±íÀï²éµ½xµÄÖµÄØ£¿ÎÒÔõôҲÕÒ²»µ½fooÍâÃ潫x¸³Öµµ½global±íµÄ²¿·Ö£¬Çó½ÌÁË£¡
            _______________________________________________
            python-chinese 
            Post: send python-chinese在lists.python.cn
            Subscribe: send subscribe to python-chinese-request在lists.python.cn 
            Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
            Detail Info: http://python.cn/mailman/listinfo/python-chinese 



          -- 
          »¶Ó­·ÃÎÊ£º
          http://blog.csdn.net/ccat

          ÁõöÎ
          March.Liu 



----------------------------------------------------------------------


          _______________________________________________
          python-chinese
          Post: send python-chinese在lists.python.cn
          Subscribe: send subscribe to python-chinese-request在lists.python.cn
          Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
          Detail Info: http://python.cn/mailman/listinfo/python-chinese 


        _______________________________________________
        python-chinese
        Post: send python-chinese在lists.python.cn 
        Subscribe: send subscribe to python-chinese-request在lists.python.cn
        Unsubscribe: send unsubscribe to   python-chinese-request在lists.python.cn
        Detail Info: http://python.cn/mailman/listinfo/python-chinese




      -- 
      Robert
      PythonÔ´ÂëÆÊÎö¡ª¡ªhttp://blog.donews.com/lemur/ 


--------------------------------------------------------------------------


      _______________________________________________
      python-chinese
      Post: send python-chinese在lists.python.cn
      Subscribe: send subscribe to python-chinese-request在lists.python.cn
      Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
      Detail Info: http://python.cn/mailman/listinfo/python-chinese


    _______________________________________________
    python-chinese
    Post: send python-chinese在lists.python.cn 
    Subscribe: send subscribe to python-chinese-request在lists.python.cn
    Unsubscribe: send unsubscribe to   python-chinese-request在lists.python.cn
    Detail Info: http://python.cn/mailman/listinfo/python-chinese




  -- 
  Robert
  PythonÔ´ÂëÆÊÎö¡ª¡ªhttp://blog.donews.com/lemur/ 


------------------------------------------------------------------------------


  _______________________________________________
  python-chinese
  Post: send python-chinese在lists.python.cn
  Subscribe: send subscribe to python-chinese-request在lists.python.cn
  Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
  Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061129/77285133/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年11月29日 星期三 17:14

Liming_Do Liming_Do在smics.com
星期三 十一月 29 17:14:12 HKT 2006

RobertÐÖ£¬É¶Ê±ºòÄÜÓпհÑгɹûʵµØ¸ø´ó»ï¶ù½²½²°¡?

-----Original Message-----
From: python-chinese-bounces在lists.python.cn [mailto:python-chinese-bounces在lists.python.cn]On Behalf Of Robert Chen
Sent: Wednesday, November 29, 2006 4:42 PM
To: python-chinese在lists.python.cn
Subject: Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡


ºÇºÇÐǪ̈¿ÍÆøÁË£¬Ô´ÂëÆÊÎöϵÁÐÍ£ÁËÏÂÀ´Ô­ÒòÓж෽Ã棬ºÇºÇ²»¹ýÖ÷Òª»¹ÊÇ×Ô¼º±È½ÏÀÁ£¬¹ý¶Îʱ¼ä×¼±¸ÖØпªÊ¼·¢²¼£¬½«Ä¿Ç°ÎªÖ¹ËùÓеķÖÎö½á¹û¹²Ïí³öÀ´¡£

²»¹ýºÜ³¤Ò»¶Îʱ¼äûÓп´PythonµÄÔ´ÂëÁË£¬ÒÔÇ°·ÖÎöµÄ½á¹ûÒ²ÍüµÃ²î²»¶àÁË£¬ÄãµÄÎÊÌâÎÒ»¹Õæ²»ºÃ»Ø´ð£¬±§Ç¸¡£²»¹ý»¹ºÃµ±Ê±¼Ç¼ÓÐÎĵµ£¬ÕùÈ¡¹ý¶Îʱ¼ä¾Í°ÑËüÃÇshare³öÀ´£¬¾ÍÏñÏÖÔÚµÄDjango BookÒ»ÑùºÇºÇ¡£µ½Ê±ºòÏ£ÍûºÍÐǪ̈¶à¶àÌÖÂÛ £º£©


On 11/29/06, libing < imlibing在163.com> wrote: 

ÖÕÓڵȵ½´óÏÀµÄ»ØÐÅÁË£¬´óÏÀµÄcpythonÔ´ÂëÆÊÎöϵÁÐÔõô¾ÍÍ£ÁËÄØ?ÎÒ»¹µÈ×ŰݶÁÄØ¡£
 
ÄÇô»¹ÓиöÎÊÌ⣺һ¶ÎÄÚ²ã´úÂëÀïÃæµÄlocalµÄ±äÁ¿µÄ´æ´¢¶àÓÃSTORE_FASTºÍLOAD_FASTÖ±½Ó´æÔÚframeÉÏ£¬ÎªÊ²Ã´»¹Òª·ÑʼӸölocal²ÎÊý´«½øÀ´Ò»¸ö±íÄØ£¿
ʲôÇé¿öÏ»áרÃÅ´«½øÀ´Ò»¸ölocal±í£¿


----- Original Message ----- 
From: Robert Chen search.pythoner在gmail.com>  
To: python-chinese在lists.python.cn 

Sent: Wednesday, November 29, 2006 3:53 PM
Subject: Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡

ºÇºÇ£¬Ô­ÒòºÜ¼òµ¥£¬ÔÚfooÖ®ÍâµÄframeÖУ¬localºÍglobalÊÇͬһ¸ödict¡£
x = 1
def foo():
    print '================= local %d =================\n' % id(locals()), locals()
    print '================= global %d =================\n' % id(globals()), globals() 
    y = x+1
    print x
    print y

print '================= local %d =================\n' % id(locals()), locals()
print '================= global %d =================\n' % id(globals()), globals()
foo()
print x

´ÓÊä³öµÄ½á¹ûÖпÉÒÔ¿´µ½ÕâÒ»µã£¬ËùÒÔfooÖ®ÍâÏòlocalÖÐÉèÖÃÖµ¾ÍÊÇÏòglobalÖÐÉèÖÃÖµ¡£


On 11/29/06, libing < imlibing在163.com> wrote: 


  3           0 LOAD_GLOBAL              0 (x)
ÕâÌõÊÇfoo´ÓglobalÀï²éxµÄ£¬globalÓÖÊÇ´ÓfooÍâÃæ´«½øÀ´µÄ£¬µ«ÊÇÎÊÌâÊÇÔÚfooÍâÃæûÓп´µ½ÍùglobalÉèxÖµµÄ´úÂ룬ÓеÄÖ»ÊÇ

              3 STORE_NAME               0 (x)
ÕâÌõ£¬ÕâÊÇÍùfooÍâÃæµÄlocal²åÊý¾ÝµÄ


----- Original Message ----- 
From: ÁõöÎ march.liu在gmail.com>  
To: python-chinese在lists.python.cn 
Sent: Wednesday, November 29, 2006 11:03 AM
Subject: Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡

Ó¦¸ÃÊÇÕâÌõ
  3           0 LOAD_GLOBAL              0 (x)
ÎÒ²ÂÏëÊǽâÊÍÆ÷±àÒëfooµÄʱºò£¬ÔÚfooÄÚ²¿ÕÒ²»µ½xµÄ¸³Öµ£¬¾ÍÖ±½ÓÔÚ×îÇ°Ãæ²åÈëÁËÕâ¸öÖ¸Áî¡£


2006/11/29, libing < imlibing在163.com>: 

hello,´ó¼ÒºÃ£¬Ð¡µÜ×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡

¶ÔÒ»¶Î´úÂ룺
x = 1
def foo():
y = x+1 
print x
print y
foo()
print x

ÎÒ´òÓ¡³öËüµÄcode object ½á¹¹³öÀ´·ÖÎö£º
£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
co_names : ('x', 'foo')
co_varnames : ()
co_freevars : ()
co_cellvars : ()
  1           0 LOAD_CONST               0 (1)
              3 STORE_NAME               0 (x)

  2           6 LOAD_CONST               1 ()

nest code object begin <<<<<
co_names : ('x',)
co_varnames : ('y',)
co_freevars : ()
co_cellvars : ()
  3           0 LOAD_GLOBAL              0 (x)
              3 LOAD_CONST               1 (1) 
              6 BINARY_ADD
              7 STORE_FAST               0 (y)

  4          10 LOAD_GLOBAL              0 (x)
             13 PRINT_ITEM
             14 PRINT_NEWLINE

  5          15 LOAD_FAST                0 (y) 
             18 PRINT_ITEM
             19 PRINT_NEWLINE
             20 LOAD_CONST               0 (None)
             23 RETURN_VALUE
nest code object end >>>>>

              9 MAKE_FUNCTION            0 
             12 STORE_NAME               1 (foo)

  6          15 LOAD_NAME                1 (foo)
             18 CALL_FUNCTION            0
             21 POP_TOP

  7          22 LOAD_NAME                0 (x) 
             25 PRINT_ITEM
             26 PRINT_NEWLINE
             27 LOAD_CONST               2 (None)
             30 RETURN_VALUE
£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½

ÔÚÍâ²ã´æxÖµµÄʱºòµÄbyte codeÊÇ              3 STORE_NAME               0 (x) 
ÔÚceval.cÔ´ÂëÀïÕâ¶Î¶ÔÓ¦µÄÊÇ
  case STORE_NAME:
   w = GETITEM(names, oparg);
   v = POP();
   if ((x = f->f_locals) != NULL) {
    if (PyDict_CheckExact(x))
     err = PyDict_SetItem(x, w, v);
    else
     err = PyObject_SetItem(x, w, v);
    Py_DECREF(v);
    if (err == 0) continue;
    break;
   }
   PyErr_Format(PyExc_SystemError,
         "no locals found when storing %s",
         PyObject_REPR(w)); 
   break;

ÕâÊÇ´æÔÚfooÍâ²ãframeµÄµÄlocalÀï°É£¿µ«ÊÇÍâ²ãbyte codeÀïxûÓÐÔÚco_varnamesÀïÃ棬ÄÇôËü¾ÍÓ¦¸ÃÔÚglobalÀï°É£¿
fooÀïÃæÓÖÈçºÎ´ÓÍâ²ã´«½øÀ´µÄglobal±íÀï²éµ½xµÄÖµÄØ£¿ÎÒÔõôҲÕÒ²»µ½fooÍâÃ潫x¸³Öµµ½global±íµÄ²¿·Ö£¬Çó½ÌÁË£¡
_______________________________________________
python-chinese 
Post: send python-chinese在lists.python.cn
Subscribe: send subscribe to python-chinese-request在lists.python.cn  python-chinese-request在lists.python.cn> 
Unsubscribe: send unsubscribe to   python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese  <http://python.cn/mailman/listinfo/python-chinese> 




-- 
»¶Ó­·ÃÎÊ£º
http://blog.csdn.net/ccat

ÁõöÎ
March.Liu 




  _____  



_______________________________________________
python-chinese
Post: send python-chinese在lists.python.cn
Subscribe: send subscribe to python-chinese-request在lists.python.cn
Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese 




_______________________________________________
python-chinese
Post: send python-chinese在lists.python.cn 
Subscribe: send subscribe to python-chinese-request在lists.python.cn
Unsubscribe: send unsubscribe to   python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese





-- 
Robert
PythonÔ´ÂëÆÊÎö¡ª¡ªhttp://blog.donews.com/lemur/ 



  _____  



_______________________________________________
python-chinese
Post: send python-chinese在lists.python.cn
Subscribe: send subscribe to python-chinese-request在lists.python.cn
Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese 




_______________________________________________
python-chinese
Post: send python-chinese在lists.python.cn 
Subscribe: send subscribe to python-chinese-request在lists.python.cn
Unsubscribe: send unsubscribe to   python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese





-- 
Robert
PythonÔ´ÂëÆÊÎö¡ª¡ªhttp://blog.donews.com/lemur/ 

-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061129/092a1e0c/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年11月29日 星期三 17:42

Robert Chen search.pythoner在gmail.com
星期三 十一月 29 17:42:23 HKT 2006

ºÇºÇ£¬±§Ç¸¹þ£¬ÎÒÒѾ­»»¹¤×÷µ½±±¾©ÁË£¬¹À¼Æ»ª¶«µÄPythoner¾Û»áÒÔºóûʲô»ú»á²Î¼ÓÁË¡£²»¹ýÎһᾡ¿ìÔÚblogÉÏshare³öÀ´µÄ £º£©

On 11/29/06, Liming_Do <Liming_Do在smics.com> wrote:
>
>  RobertÐÖ£¬É¶Ê±ºòÄÜÓпհÑгɹûʵµØ¸ø´ó»ï¶ù½²½²°¡?
>
> -----Original Message-----
> *From:* python-chinese-bounces在lists.python.cn [mailto:
> python-chinese-bounces在lists.python.cn]*On Behalf Of *Robert Chen
> *Sent:* Wednesday, November 29, 2006 4:42 PM
> *To:* python-chinese在lists.python.cn
> *Subject:* Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡
>
> ºÇºÇÐǪ̈¿ÍÆøÁË£¬Ô´ÂëÆÊÎöϵÁÐÍ£ÁËÏÂÀ´Ô­ÒòÓж෽Ã棬ºÇºÇ²»¹ýÖ÷Òª»¹ÊÇ×Ô¼º±È½ÏÀÁ£¬¹ý¶Îʱ¼ä×¼±¸ÖØпªÊ¼·¢²¼£¬½«Ä¿Ç°ÎªÖ¹ËùÓеķÖÎö½á¹û¹²Ïí³öÀ´¡£
>
> ²»¹ýºÜ³¤Ò»¶Îʱ¼äûÓп´PythonµÄÔ´ÂëÁË£¬ÒÔÇ°·ÖÎöµÄ½á¹ûÒ²ÍüµÃ²î²»¶àÁË£¬ÄãµÄÎÊÌâÎÒ»¹Õæ²»ºÃ»Ø´ð£¬±§Ç¸¡£²»¹ý»¹ºÃµ±Ê±¼Ç¼ÓÐÎĵµ£¬ÕùÈ¡¹ý¶Îʱ¼ä¾Í°ÑËüÃÇshare³öÀ´£¬¾ÍÏñÏÖÔÚµÄDjango
> BookÒ»ÑùºÇºÇ¡£µ½Ê±ºòÏ£ÍûºÍÐǪ̈¶à¶àÌÖÂÛ £º£©
>
> On 11/29/06, libing <imlibing在163.com> wrote:
> >
> >  ÖÕÓڵȵ½´óÏÀµÄ»ØÐÅÁË£¬´óÏÀµÄcpythonÔ´ÂëÆÊÎöϵÁÐÔõô¾ÍÍ£ÁËÄØ?ÎÒ»¹µÈ×ŰݶÁÄØ¡£
> >
> >
> > ÄÇô»¹ÓиöÎÊÌ⣺һ¶ÎÄÚ²ã´úÂëÀïÃæµÄlocalµÄ±äÁ¿µÄ´æ´¢¶àÓÃSTORE_FASTºÍLOAD_FASTÖ±½Ó´æÔÚframeÉÏ£¬ÎªÊ²Ã´»¹Òª·ÑʼӸölocal²ÎÊý´«½øÀ´Ò»¸ö±íÄØ£¿
> > ʲôÇé¿öÏ»áרÃÅ´«½øÀ´Ò»¸ölocal±í£¿
> >
> > ----- Original Message -----
> > *From:* Robert Chen <search.pythoner在gmail.com>
> > *To:* python-chinese在lists.python.cn
> >  *Sent:* Wednesday, November 29, 2006 3:53 PM
> > *Subject:* Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡
> >
> > ºÇºÇ£¬Ô­ÒòºÜ¼òµ¥£¬ÔÚfooÖ®ÍâµÄframeÖУ¬localºÍglobalÊÇͬһ¸ödict¡£
> > x = 1
> > def foo():
> >     print '================= local %d =================\n' %
> > id(locals()), locals()
> >     print '================= global %d =================\n' %
> > id(globals()), globals()
> >     y = x+1
> >     print x
> >     print y
> >
> > print '================= local %d =================\n' % id(locals()),
> > locals()
> > print '================= global %d =================\n' % id(globals()),
> > globals()
> > foo()
> > print x
> >
> > ´ÓÊä³öµÄ½á¹ûÖпÉÒÔ¿´µ½ÕâÒ»µã£¬ËùÒÔfooÖ®ÍâÏòlocalÖÐÉèÖÃÖµ¾ÍÊÇÏòglobalÖÐÉèÖÃÖµ¡£
> >
> > On 11/29/06, libing <imlibing在163.com> wrote:
> > >
> > >    3           0 LOAD_GLOBAL              0 (x)
> > > ÕâÌõÊÇfoo´ÓglobalÀï²éxµÄ£¬globalÓÖÊÇ´ÓfooÍâÃæ´«½øÀ´µÄ£¬µ«ÊÇÎÊÌâÊÇÔÚfooÍâÃæûÓп´µ½ÍùglobalÉèxÖµµÄ´úÂ룬ÓеÄÖ»ÊÇ
> > >               3 STORE_NAME               0 (x)
> > > ÕâÌõ£¬ÕâÊÇÍùfooÍâÃæµÄlocal²åÊý¾ÝµÄ
> > >
> > >  ----- Original Message -----
> > > *From:* ÁõöÎ <march.liu在gmail.com>
> > > *To:* python-chinese在lists.python.cn
> > > *Sent:* Wednesday, November 29, 2006 11:03 AM
> > > *Subject:* Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡
> > >
> > > Ó¦¸ÃÊÇÕâÌõ
> > >   3           0 LOAD_GLOBAL              0 (x)
> > > ÎÒ²ÂÏëÊǽâÊÍÆ÷±àÒëfooµÄʱºò£¬ÔÚfooÄÚ²¿ÕÒ²»µ½xµÄ¸³Öµ£¬¾ÍÖ±½ÓÔÚ×îÇ°Ãæ²åÈëÁËÕâ¸öÖ¸Áî¡£
> > >
> > > 2006/11/29, libing <imlibing在163.com>:
> > > >
> > > > hello,´ó¼ÒºÃ£¬Ð¡µÜ×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡
> > > >
> > > > ¶ÔÒ»¶Î´úÂ룺
> > > > x = 1
> > > > def foo():
> > > > y = x+1
> > > > print x
> > > > print y
> > > > foo()
> > > > print x
> > > >
> > > > ÎÒ´òÓ¡³öËüµÄcode object ½á¹¹³öÀ´·ÖÎö£º
> > > > £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
> > > > co_names : ('x', 'foo')
> > > > co_varnames : ()
> > > > co_freevars : ()
> > > > co_cellvars : ()
> > > >   1           0 LOAD_CONST               0 (1)
> > > >               3 STORE_NAME               0 (x)
> > > >
> > > >   2           6 LOAD_CONST               1 (> > > > 010167B8, file "string", line 2>)
> > > >
> > > > nest code object begin <<<<<
> > > > co_names : ('x',)
> > > > co_varnames : ('y',)
> > > > co_freevars : ()
> > > > co_cellvars : ()
> > > >   3           0 LOAD_GLOBAL              0 (x)
> > > >               3 LOAD_CONST               1 (1)
> > > >               6 BINARY_ADD
> > > >               7 STORE_FAST               0 (y)
> > > >
> > > >   4          10 LOAD_GLOBAL              0 (x)
> > > >              13 PRINT_ITEM
> > > >              14 PRINT_NEWLINE
> > > >
> > > >   5          15 LOAD_FAST                0 (y)
> > > >              18 PRINT_ITEM
> > > >              19 PRINT_NEWLINE
> > > >              20 LOAD_CONST               0 (None)
> > > >              23 RETURN_VALUE
> > > > nest code object end >>>>>
> > > >
> > > >               9 MAKE_FUNCTION            0
> > > >              12 STORE_NAME               1 (foo)
> > > >
> > > >   6          15 LOAD_NAME                1 (foo)
> > > >              18 CALL_FUNCTION            0
> > > >              21 POP_TOP
> > > >
> > > >   7          22 LOAD_NAME                0 (x)
> > > >              25 PRINT_ITEM
> > > >              26 PRINT_NEWLINE
> > > >              27 LOAD_CONST               2 (None)
> > > >              30 RETURN_VALUE
> > > > £½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
> > > >
> > > > ÔÚÍâ²ã´æxÖµµÄʱºòµÄbyte codeÊÇ              3 STORE_NAME               0 (x)
> > > > ÔÚceval.cÔ´ÂëÀïÕâ¶Î¶ÔÓ¦µÄÊÇ
> > > >   case STORE_NAME:
> > > >    w = GETITEM(names, oparg);
> > > >    v = POP();
> > > >    if ((x = f->f_locals) != NULL) {
> > > >     if (PyDict_CheckExact(x))
> > > >      err = PyDict_SetItem(x, w, v);
> > > >     else
> > > >      err = PyObject_SetItem(x, w, v);
> > > >     Py_DECREF(v);
> > > >     if (err == 0) continue;
> > > >     break;
> > > >    }
> > > >    PyErr_Format(PyExc_SystemError,
> > > >          "no locals found when storing %s",
> > > >          PyObject_REPR(w));
> > > >    break;
> > > >
> > > > ÕâÊÇ´æÔÚfooÍâ²ãframeµÄµÄlocalÀï°É£¿µ«ÊÇÍâ²ãbyte
> > > > codeÀïxûÓÐÔÚco_varnamesÀïÃ棬ÄÇôËü¾ÍÓ¦¸ÃÔÚglobalÀï°É£¿
> > > > fooÀïÃæÓÖÈçºÎ´ÓÍâ²ã´«½øÀ´µÄglobal±íÀï²éµ½xµÄÖµÄØ£¿ÎÒÔõôҲÕÒ²»µ½fooÍâÃ潫x¸³Öµµ½global±íµÄ²¿·Ö£¬Çó½ÌÁË£¡
> > > > _______________________________________________
> > > > python-chinese
> > > > Post: send python-chinese在lists.python.cn
> > > > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > > > Unsubscribe: send unsubscribe to
> > > > python-chinese-request在lists.python.cn
> > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > >
> > >
> > >
> > >
> > > --
> > > »¶Ó­·ÃÎÊ£º
> > > http://blog.csdn.net/ccat
> > >
> > > ÁõöÎ
> > > March.Liu
> > >
> > > ------------------------------
> > >
> > > _______________________________________________
> > > python-chinese
> > > Post: send python-chinese在lists.python.cn
> > > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > > Unsubscribe: send unsubscribe to
> > > python-chinese-request在lists.python.cn
> > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > >
> > >
> > > _______________________________________________
> > > python-chinese
> > > Post: send python-chinese在lists.python.cn
> > > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > > Unsubscribe: send unsubscribe to
> > > python-chinese-request在lists.python.cn
> > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > >
> >
> >
> >
> > --
> > Robert
> > PythonÔ´ÂëÆÊÎö¡ª¡ªhttp://blog.donews.com/lemur/
> >
> > ------------------------------
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
>
>
>
> --
> Robert
> PythonÔ´ÂëÆÊÎö¡ª¡ªhttp://blog.donews.com/lemur/
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>



-- 
Robert
PythonÔ´ÂëÆÊÎö¡ª¡ªhttp://blog.donews.com/lemur/
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061129/477af39b/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年11月29日 星期三 18:34

Liming_Do Liming_Do在smics.com
星期三 十一月 29 18:34:43 HKT 2006

:)ÄÇÒ²ºÃ°¡

-----Original Message-----
From: python-chinese-bounces在lists.python.cn [mailto:python-chinese-bounces在lists.python.cn]On Behalf Of Robert Chen
Sent: Wednesday, November 29, 2006 5:42 PM
To: python-chinese在lists.python.cn
Subject: Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡


ºÇºÇ£¬±§Ç¸¹þ£¬ÎÒÒѾ­»»¹¤×÷µ½±±¾©ÁË£¬¹À¼Æ»ª¶«µÄPythoner¾Û»áÒÔºóûʲô»ú»á²Î¼ÓÁË¡£²»¹ýÎһᾡ¿ìÔÚblogÉÏshare³öÀ´µÄ £º£©


On 11/29/06, Liming_Do < Liming_Do在smics.com > wrote: 

RobertÐÖ£¬É¶Ê±ºòÄÜÓпհÑгɹûʵµØ¸ø´ó»ï¶ù½²½²°¡?

-----Original Message-----
From: python-chinese-bounces在lists.python.cn [mailto: python-chinese-bounces在lists.python.cn]On Behalf Of Robert Chen
Sent: Wednesday, November 29, 2006 4:42 PM
To: python-chinese在lists.python.cn

Subject: Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡


ºÇºÇÐǪ̈¿ÍÆøÁË£¬Ô´ÂëÆÊÎöϵÁÐÍ£ÁËÏÂÀ´Ô­ÒòÓж෽Ã棬ºÇºÇ²»¹ýÖ÷Òª»¹ÊÇ×Ô¼º±È½ÏÀÁ£¬¹ý¶Îʱ¼ä×¼±¸ÖØпªÊ¼·¢²¼£¬½«Ä¿Ç°ÎªÖ¹ËùÓеķÖÎö½á¹û¹²Ïí³öÀ´¡£

²»¹ýºÜ³¤Ò»¶Îʱ¼äûÓп´PythonµÄÔ´ÂëÁË£¬ÒÔÇ°·ÖÎöµÄ½á¹ûÒ²ÍüµÃ²î²»¶àÁË£¬ÄãµÄÎÊÌâÎÒ»¹Õæ²»ºÃ»Ø´ð£¬±§Ç¸¡£²»¹ý»¹ºÃµ±Ê±¼Ç¼ÓÐÎĵµ£¬ÕùÈ¡¹ý¶Îʱ¼ä¾Í°ÑËüÃÇshare³öÀ´£¬¾ÍÏñÏÖÔÚµÄDjango BookÒ»ÑùºÇºÇ¡£µ½Ê±ºòÏ£ÍûºÍÐǪ̈¶à¶àÌÖÂÛ £º£©


On 11/29/06, libing < imlibing在163.com> wrote: 

ÖÕÓڵȵ½´óÏÀµÄ»ØÐÅÁË£¬´óÏÀµÄcpythonÔ´ÂëÆÊÎöϵÁÐÔõô¾ÍÍ£ÁËÄØ?ÎÒ»¹µÈ×ŰݶÁÄØ¡£
 
ÄÇô»¹ÓиöÎÊÌ⣺һ¶ÎÄÚ²ã´úÂëÀïÃæµÄlocalµÄ±äÁ¿µÄ´æ´¢¶àÓÃSTORE_FASTºÍLOAD_FASTÖ±½Ó´æÔÚframeÉÏ£¬ÎªÊ²Ã´»¹Òª·ÑʼӸölocal²ÎÊý´«½øÀ´Ò»¸ö±íÄØ£¿
ʲôÇé¿öÏ»áרÃÅ´«½øÀ´Ò»¸ölocal±í£¿


----- Original Message ----- 
From: Robert Chen search.pythoner在gmail.com>  
To: python-chinese在lists.python.cn 

Sent: Wednesday, November 29, 2006 3:53 PM
Subject: Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡

ºÇºÇ£¬Ô­ÒòºÜ¼òµ¥£¬ÔÚfooÖ®ÍâµÄframeÖУ¬localºÍglobalÊÇͬһ¸ödict¡£
x = 1
def foo():
    print '================= local %d =================\n' % id(locals()), locals()
    print '================= global %d =================\n' % id(globals()), globals() 
    y = x+1
    print x
    print y

print '================= local %d =================\n' % id(locals()), locals()
print '================= global %d =================\n' % id(globals()), globals()
foo()
print x

´ÓÊä³öµÄ½á¹ûÖпÉÒÔ¿´µ½ÕâÒ»µã£¬ËùÒÔfooÖ®ÍâÏòlocalÖÐÉèÖÃÖµ¾ÍÊÇÏòglobalÖÐÉèÖÃÖµ¡£


On 11/29/06, libing < imlibing在163.com> wrote: 


  3           0 LOAD_GLOBAL              0 (x)
ÕâÌõÊÇfoo´ÓglobalÀï²éxµÄ£¬globalÓÖÊÇ´ÓfooÍâÃæ´«½øÀ´µÄ£¬µ«ÊÇÎÊÌâÊÇÔÚfooÍâÃæûÓп´µ½ÍùglobalÉèxÖµµÄ´úÂ룬ÓеÄÖ»ÊÇ

              3 STORE_NAME               0 (x)
ÕâÌõ£¬ÕâÊÇÍùfooÍâÃæµÄlocal²åÊý¾ÝµÄ


----- Original Message ----- 
From: ÁõöÎ march.liu在gmail.com>  
To: python-chinese在lists.python.cn 
Sent: Wednesday, November 29, 2006 11:03 AM
Subject: Re: [python-chinese]×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡

Ó¦¸ÃÊÇÕâÌõ
  3           0 LOAD_GLOBAL              0 (x)
ÎÒ²ÂÏëÊǽâÊÍÆ÷±àÒëfooµÄʱºò£¬ÔÚfooÄÚ²¿ÕÒ²»µ½xµÄ¸³Öµ£¬¾ÍÖ±½ÓÔÚ×îÇ°Ãæ²åÈëÁËÕâ¸öÖ¸Áî¡£


2006/11/29, libing < imlibing在163.com>: 

hello,´ó¼ÒºÃ£¬Ð¡µÜ×î½üÔÚÑо¿pythonÔ´Â룬ÓиöÎÊÌâ¸ã²»Ã÷°×£¬Çó½Ì£¡

¶ÔÒ»¶Î´úÂ룺
x = 1
def foo():
y = x+1 
print x
print y
foo()
print x

ÎÒ´òÓ¡³öËüµÄcode object ½á¹¹³öÀ´·ÖÎö£º
£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
co_names : ('x', 'foo')
co_varnames : ()
co_freevars : ()
co_cellvars : ()
  1           0 LOAD_CONST               0 (1)
              3 STORE_NAME               0 (x)

  2           6 LOAD_CONST               1 ()

nest code object begin <<<<<
co_names : ('x',)
co_varnames : ('y',)
co_freevars : ()
co_cellvars : ()
  3           0 LOAD_GLOBAL              0 (x)
              3 LOAD_CONST               1 (1) 
              6 BINARY_ADD
              7 STORE_FAST               0 (y)

  4          10 LOAD_GLOBAL              0 (x)
             13 PRINT_ITEM
             14 PRINT_NEWLINE

  5          15 LOAD_FAST                0 (y) 
             18 PRINT_ITEM
             19 PRINT_NEWLINE
             20 LOAD_CONST               0 (None)
             23 RETURN_VALUE
nest code object end >>>>>

              9 MAKE_FUNCTION            0 
             12 STORE_NAME               1 (foo)

  6          15 LOAD_NAME                1 (foo)
             18 CALL_FUNCTION            0
             21 POP_TOP

  7          22 LOAD_NAME                0 (x) 
             25 PRINT_ITEM
             26 PRINT_NEWLINE
             27 LOAD_CONST               2 (None)
             30 RETURN_VALUE
£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½

ÔÚÍâ²ã´æxÖµµÄʱºòµÄbyte codeÊÇ              3 STORE_NAME               0 (x) 
ÔÚceval.cÔ´ÂëÀïÕâ¶Î¶ÔÓ¦µÄÊÇ
  case STORE_NAME:
   w = GETITEM(names, oparg);
   v = POP();
   if ((x = f->f_locals) != NULL) {
    if (PyDict_CheckExact(x))
     err = PyDict_SetItem(x, w, v);
    else
     err = PyObject_SetItem(x, w, v);
    Py_DECREF(v);
    if (err == 0) continue;
    break;
   }
   PyErr_Format(PyExc_SystemError,
         "no locals found when storing %s",
         PyObject_REPR(w)); 
   break;

ÕâÊÇ´æÔÚfooÍâ²ãframeµÄµÄlocalÀï°É£¿µ«ÊÇÍâ²ãbyte codeÀïxûÓÐÔÚco_varnamesÀïÃ棬ÄÇôËü¾ÍÓ¦¸ÃÔÚglobalÀï°É£¿
fooÀïÃæÓÖÈçºÎ´ÓÍâ²ã´«½øÀ´µÄglobal±íÀï²éµ½xµÄÖµÄØ£¿ÎÒÔõôҲÕÒ²»µ½fooÍâÃ潫x¸³Öµµ½global±íµÄ²¿·Ö£¬Çó½ÌÁË£¡
_______________________________________________
python-chinese 
Post: send python-chinese在lists.python.cn
Subscribe: send subscribe to python-chinese-request在lists.python.cn  python-chinese-request在lists.python.cn> 
Unsubscribe: send unsubscribe to   python-chinese-request在lists.python.cn 
Detail Info: http://python.cn/mailman/listinfo/python-chinese  <http://python.cn/mailman/listinfo/python-chinese> 




-- 
»¶Ó­·ÃÎÊ£º
http://blog.csdn.net/ccat

ÁõöÎ
March.Liu 




  _____  



_______________________________________________
python-chinese
Post: send python-chinese在lists.python.cn
Subscribe: send subscribe to python-chinese-request在lists.python.cn
Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese 




_______________________________________________
python-chinese
Post: send python-chinese在lists.python.cn 
Subscribe: send subscribe to python-chinese-request在lists.python.cn
Unsubscribe: send unsubscribe to   python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese





-- 
Robert
PythonÔ´ÂëÆÊÎö¡ª¡ªhttp://blog.donews.com/lemur/ 



  _____  



_______________________________________________
python-chinese
Post: send python-chinese在lists.python.cn
Subscribe: send subscribe to python-chinese-request在lists.python.cn
Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese 




_______________________________________________
python-chinese
Post: send python-chinese在lists.python.cn 
Subscribe: send subscribe to python-chinese-request在lists.python.cn
Unsubscribe: send unsubscribe to   python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese





-- 
Robert
PythonÔ´ÂëÆÊÎö¡ª¡ªhttp://blog.donews.com/lemur/ 


_______________________________________________
python-chinese
Post: send python-chinese在lists.python.cn 
Subscribe: send subscribe to python-chinese-request在lists.python.cn
Unsubscribe: send unsubscribe to   python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese





-- 
Robert
PythonÔ´ÂëÆÊÎö¡ª¡ªhttp://blog.donews.com/lemur/ 

-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061129/17007f85/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号