Python论坛  - 讨论区

标题:[python-chinese] (无主题)

2006年11月09日 星期四 09:28

Jin Qing jinq0123在163.com
星期四 十一月 9 09:28:35 HKT 2006

iamzcyhit,您好! 

有什么问题?我看没什么问题。  

======== 2006-11-07 18:15:00 您在来信中写道: ========

为什么这段代码的输出最后竟然有问题?
class Person:
    '''Represents a person.'''
    population = 0

    def __init__(self,name):
        '''Initializing the person's data.'''
        self.name = name
        print '(Initializing %s)' %self.name

        Person.population += 1
    def __del__(self):
        '''I am dying'''
        print '%s says bye.' %self.name
        Person.population -= 1

        if Person.population == 0:
            print 'I am the last one'
        else:
            print 'There are still %d person left' %Person.population
    def sayHi(self):
        '''Greeting by the person.
        really,that's all it does.'''
        print 'hello,I am %s' %self.name
    def howMany(self):
        '''print the current population.'''
        if Person.population == 1:
            print 'I am the only person here'
        else:
            print 'We have %d persons' %Person.population

iamzcy = Person('iamzcy')
iamzcy.sayHi()
iamzcy.howMany()

sam = Person('sam')
sam.sayHi()
sam.howMany()

iamzcy.sayHi()
iamzcy.howMany()

 



iamzcyhit
2006-11-07

= = = = = = = = = = = = = = = = = = = = = = 
        致
礼!

              Jin Qing
              jinq0123 at 163.com
                 2006-11-09




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

2006年11月09日 星期四 10:10

nmweizi nmweizi在163.com
星期四 十一月 9 10:10:31 HKT 2006

python-chinese£¬ÄãºÃ

ÊÔÁËÒ»ÏÂûÓÐʲô´óÎÊÌâ¡£Ö»ÊÇÔÚ×îºóÍƳöʱdel·½·¨Ìáʾ´íÎ󡣸ijÉÕâÑù¾Í¿ÉÒÔÁË¡£


class Person:
    '''Represents a person.'''
    population = 0
    def __init__(self,name):
        '''Initializing the person's data.'''
        self.name = name
        print '(Initializing %s)' %self.name
        Person.population += 1
    def __del__(self):
        '''I am dying'''
        print '%s says bye.' %self.name
        
        if not Person:
            return
        Person.population -= 1
        if Person.population == 0:
            print 'I am the last one'
        else:
            print 'There are still %d person left' %Person.population
    def sayHi(self):
        '''Greeting by the person.
        really,that's all it does.'''
        print 'hello,I am %s' %self.name
    def howMany(self):
        '''print the current population.'''
        if Person.population == 1:
            print 'I am the only person here'
        else:
            print 'We have %d persons' %Person.population
iamzcy = Person('iamzcy')
iamzcy.sayHi()
iamzcy.howMany()
sam = Person('sam')
sam.sayHi()
sam.howMany()
del sam
iamzcy.sayHi()
iamzcy.howMany()




Ö´Ðнá¹ûÈçÏ£º
(Initializing iamzcy)
hello,I am iamzcy
I am the only person here
(Initializing sam)
hello,I am sam
We have 2 persons
sam says bye.
There are still 1 person left
hello,I am iamzcy
I am the only person here
iamzcy says bye.


nmweizi£¬nmweizi在163.com
2006-11-09 
----- Original Message ----- 

From: Jin Qing 
To: python-chinese在lists.python.cn 
Sent: 2006-11-09, 09:28:35
Subject: Re: [python-chinese] (ÎÞÖ÷Ìâ)


iamzcyhit£¬ÄúºÃ£¡ 

ÓÐʲôÎÊÌ⣿ÎÒ¿´Ã»Ê²Ã´ÎÊÌâ¡£¡¡¡¡

======== 2006-11-07 18:15:00 ÄúÔÚÀ´ÐÅÖÐдµÀ£º ========

ΪʲôÕâ¶Î´úÂëµÄÊä³ö×îºó¾¹È»ÓÐÎÊÌ⣿
class Person:
    '''Represents a person.'''
    population = 0

    def __init__(self,name):
        '''Initializing the person's data.'''
        self.name = name
        print '(Initializing %s)' %self.name

        Person.population += 1
    def __del__(self):
        '''I am dying'''
        print '%s says bye.' %self.name
        Person.population -= 1

        if Person.population == 0:
            print 'I am the last one'
        else:
            print 'There are still %d person left' %Person.population
    def sayHi(self):
        '''Greeting by the person.
        really,that's all it does.'''
        print 'hello,I am %s' %self.name
    def howMany(self):
        '''print the current population.'''
        if Person.population == 1:
            print 'I am the only person here'
        else:
            print 'We have %d persons' %Person.population

iamzcy = Person('iamzcy')
iamzcy.sayHi()
iamzcy.howMany()

sam = Person('sam')
sam.sayHi()
sam.howMany()

iamzcy.sayHi()
iamzcy.howMany()

 



iamzcyhit
2006-11-07

= = = = = = = = = = = = = = = = = = = = = = 
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÖÂ
Àñ£¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Jin Qing
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡jinq0123在163.com
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2006-11-09



_______________________________________________
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/20061109/ca37e7f6/attachment.html 

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

2006年11月10日 星期五 00:15

Fan Hongtao fanhongtao在gmail.com
星期五 十一月 10 00:15:59 HKT 2006

On 11/9/06, nmweizi <nmweizi在163.com> wrote:
>
>  python-chinese£¬ÄãºÃ
>
> ÊÔÁËÒ»ÏÂûÓÐʲô´óÎÊÌâ¡£Ö»ÊÇÔÚ×îºóÍƳöʱdel·½·¨Ìáʾ´íÎ󡣸ijÉÕâÑù¾Í¿ÉÒÔÁË¡£
>
>
> class Person:
>     '''Represents a person.'''
>     population = 0
>     def __init__(self,name):
>         '''Initializing the person's data.'''
>         self.name = name
>         print '(Initializing %s)' %self.name
>         Person.population += 1
>     def __del__(self):
>         '''I am dying'''
>         print '%s says bye.' %self.name
>
>         if not Person:
>             return
>         Person.population -= 1
>         if Person.population == 0:
>             print 'I am the last one'
>         else:
>             print 'There are still %d person left' %Person.population
>     def sayHi(self):
>         '''Greeting by the person.
>         really,that's all it does.'''
>         print 'hello,I am %s' %self.name
>     def howMany(self):
>         '''print the current population.'''
>         if Person.population == 1:
>             print 'I am the only person here'
>         else:
>             print 'We have %d persons' %Person.population
> iamzcy = Person('iamzcy')
> iamzcy.sayHi()
> iamzcy.howMany()
> sam = Person('sam')
> sam.sayHi()
> sam.howMany()
> del sam
> iamzcy.sayHi()
> iamzcy.howMany()
>
>
>
>  Ö´Ðнá¹ûÈçÏ£º
> (Initializing iamzcy)
> hello,I am iamzcy
> I am the only person here
> (Initializing sam)
> hello,I am sam
> We have 2 persons
> sam says bye.
> There are still 1 person left
> hello,I am iamzcy
> I am the only person here
> iamzcy says bye.
>
>
> nmweizi£¬nmweizi在163.com<%3C!--AID_FROMADDRESS_BEGIN--%3Enmweizi在163.com%3C!--AID_FROMADDRESS_END--%3E>
> 2006-11-09
>
> ----- Original Message -----
>
> *From: *Jin Qing <jinq0123在163.com>
> *To: *python-chinese在lists.python.cn
> *Sent: *2006-11-09, 09:28:35
> *Subject: *Re: [python-chinese] (ÎÞÖ÷Ìâ)
>
>
>   iamzcyhit£¬ÄúºÃ£¡
>
> ÓÐʲôÎÊÌ⣿ÎÒ¿´Ã»Ê²Ã´ÎÊÌâ¡£
>
> ======== 2006-11-07 18:15:00 ÄúÔÚÀ´ÐÅÖÐдµÀ£º ========
>
> ΪʲôÕâ¶Î´úÂëµÄÊä³ö×îºó¾¹È»ÓÐÎÊÌ⣿
> class Person:
>     '''Represents a person.'''
>     population = 0
>
>     def __init__(self,name):
>         '''Initializing the person's data.'''
>         self.name = name
>         print '(Initializing %s)' %self.name
>
>         Person.population += 1
>     def __del__(self):
>         '''I am dying'''
>         print '%s says bye.' %self.name
>         Person.population -= 1
>
>         if Person.population == 0:
>             print 'I am the last one'
>         else:
>             print 'There are still %d person left' %Person.population
>     def sayHi(self):
>         '''Greeting by the person.
>         really,that's all it does.'''
>         print 'hello,I am %s' %self.name
>     def howMany(self):
>         '''print the current population.'''
>         if Person.population == 1:
>             print 'I am the only person here'
>         else:
>             print 'We have %d persons' %Person.population
>
> iamzcy = Person('iamzcy')
> iamzcy.sayHi()
> iamzcy.howMany()
>
> sam = Person('sam')
> sam.sayHi()
> sam.howMany()
>
> iamzcy.sayHi()
> iamzcy.howMany()
>
>
>
>
>
> iamzcyhit
> 2006-11-07
>
> = = = = = = = = = = = = = = = = = = = = = =
> ÖÂ
> Àñ£¡
>
> Jin Qing
> jinq0123在163.com <+jinq0123在163.com>
> 2006-11-09
>
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn<+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<+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
>



#!/usr/bin/env/ python
# -*- coding: GB2312 -*-

# ²âÊÔ
class Person:
   '''Represents a person.'''
   population = 0

   def __init__(self, name):
       '''Initializing the person's data.'''
       self.name = name
       print '(Initializing %s)' %self.name
       Person.population += 1

   def __del__(self):
       '''I am dying'''
       print '%s says bye.' %self.name

       Person.population -= 1

       if Person.population == 0:
           print 'I am the last one'
       else:
           print 'There are still %d person left' %Person.population

   def sayHi(self):
       '''Greeting by the person.
       really,that's all it does.'''
       print 'hello,I am %s' %self.name

   def howMany(self):
       '''print the current population.'''
       if Person.population == 1:
           print 'I am the only person here'
       else:
           print 'We have %d persons' %Person.population

def main():
    iamzcy = Person('iamzcy')
    iamzcy.sayHi()
    iamzcy.howMany()

    sam = Person('sam')
    sam.sayHi()
    sam.howMany()

    iamzcy.sayHi()
    iamzcy.howMany()
main()

ÕâÑùд¾Í¿ÉÒÔÔËÐУ¬½á¹ûΪ£º
(Initializing iamzcy)
hello,I am iamzcy
I am the only person here
(Initializing sam)
hello,I am sam
We have 2 persons
hello,I am iamzcy
We have 2 persons
iamzcy says bye.
There are still 1 person left
sam says bye.
I am the last one

µ«Èç¹û½«mainº¯ÊýÖеĴúÂëÒƳýµ½ main º¯ÊýÖ®Í⣬Ôò»á±¨´í£º

(Initializing iamzcy)
hello,I am iamzcy
I am the only person here
(Initializing sam)
hello,I am sam
We have 2 persons
hello,I am iamzcy
We have 2 persons
sam says bye.
There are still 1 person left
iamzcy says bye.
Exception exceptions.AttributeError: "'NoneType' object has no attribute
'population'" in <__main__.Person instance
at 0x00BF5D00>> ignored

 ¿´À´Ó¦¸ÃÊÇPythonÔÚ»ØÊÕ¶ÔÏóʱÓÐÎÊÌâ¡£


-- 
·¶ºéÌÏ
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061110/474ebc82/attachment.html 

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

2006年11月10日 星期五 09:06

amingsc amingsc在gmail.com
星期五 十一月 10 09:06:17 HKT 2006

你们试试把类名“Person”改成“aerson”看看有没有错误?
没了吧?有点怪哦
按我的理解,这也正常
在python进程退出的时候肯定会销毁其namespace:
['__builtins__', '__doc__', '__name__', 'Person', 'iamzcy', 'sam']
它肯定有一定的销毁顺序,如果Person类在iamzcy、sam之前被销毁的话那
肯定有问题,所以把Person改成aerson后就变成在iamzcy、sam之后销毁了,
所以也就没有问题了
对于在那段代码放入main函数中也好理解,因为iamzcy、sam肯定在main被销毁
之前被销毁,而Person是与main在一个时间级上被销毁的,所以。。。

一般来说class是不应该在class-object之前被销毁的,可能python设计的时候没
有考虑到
这个问题吧,也可能故意这样设计的,因为判断class与class-object也有时间开
销嘛,
再说变量的销毁也很频繁,而这种异常在真实的开发中一般遇不上的,所以有些得
不偿失。

如果你非得这么弄的话,那就显式销毁吧
del iamzcy
del sam
[del Person] #这行不用写的,反正在最后才销毁的

Fan Hongtao 写道:
>
> On 11/9/06, *nmweizi* <nmweizi at 163.com nmweizi at 163.com>> wrote:
>
>     python-chinese,你好
>     试了一下没有什么大问题。只是在最后推出时del方法提示错误。改成这样
>     就可以了。
>     class Person:
>     '''Represents a person.'''
>     population = 0
>     def __init__(self,name):
>     '''Initializing the person's data.'''
>     self.name <http://self.name/> = name
>     print '(Initializing %s)' %self.name
>     Person.population += 1
>     def __del__(self):
>     '''I am dying'''
>     print '%s says bye.' %self.name
>
>     if not Person:
>     return
>     Person.population -= 1
>     if Person.population == 0:
>     print 'I am the last one'
>     else:
>     print 'There are still %d person left' %Person.population
>     def sayHi(self):
>     '''Greeting by the person.
>     really,that's all it does.'''
>     print 'hello,I am %s' %self.name
>     def howMany(self):
>     '''print the current population.'''
>     if Person.population == 1:
>     print 'I am the only person here'
>     else:
>     print 'We have %d persons' %Person.population
>     iamzcy = Person('iamzcy')
>     iamzcy.sayHi()
>     iamzcy.howMany()
>     sam = Person('sam')
>     sam.sayHi()
>     sam.howMany()
>     del sam
>     iamzcy.sayHi()
>     iamzcy.howMany()
>     执行结果如下:
>     (Initializing iamzcy)
>     hello,I am iamzcy
>     I am the only person here
>     (Initializing sam)
>     hello,I am sam
>     We have 2 persons
>     sam says bye.
>     There are still 1 person left
>     hello,I am iamzcy
>     I am the only person here
>     iamzcy says bye.
>     nmweizi,nmweizi at 163.com
>     3Enmweizi at 163.com%3C%21--AID_FROMADDRESS_END--%3E>
>     2006-11-09
>
>         ----- Original Message -----
>         *From: *Jin Qing jinq0123 at 163.com>
>         *To: *python-chinese at lists.python.cn
>         python-chinese at lists.python.cn>
>         *Sent: *2006-11-09, 09:28:35
>         *Subject: *Re: [python-chinese] (无主题)
>
>         iamzcyhit,您好!
>
>         有什么问题?我看没什么问题。  
>
>         ======== 2006-11-07 18:15:00 您在来信中写道: ========
>
>         为什么这段代码的输出最后竟然有问题?
>         class Person:
>         '''Represents a person.'''
>         population = 0
>
>         def __init__(self,name):
>         '''Initializing the person's data.'''
>         self.name <http://self.name/> = name
>         print '(Initializing %s)' %self.name
>
>         Person.population += 1
>         def __del__(self):
>         '''I am dying'''
>         print '%s says bye.' %self.name
>         Person.population -= 1
>
>         if Person.population == 0:
>         print 'I am the last one'
>         else:
>         print 'There are still %d person left' %Person.population
>         def sayHi(self):
>         '''Greeting by the person.
>         really,that's all it does.'''
>         print 'hello,I am %s' %self.name
>         def howMany(self):
>         '''print the current population.'''
>         if Person.population == 1:
>         print 'I am the only person here'
>         else:
>         print 'We have %d persons' %Person.population
>
>         iamzcy = Person('iamzcy')
>         iamzcy.sayHi()
>         iamzcy.howMany()
>
>         sam = Person('sam')
>         sam.sayHi()
>         sam.howMany()
>
>         iamzcy.sayHi()
>         iamzcy.howMany()
>
>
>
>
>
>         iamzcyhit
>         2006-11-07
>
>         = = = = = = = = = = = = = = = = = = = = = =
>                 致
>         礼!
>
>                       Jin Qing
>                        jinq0123 at 163.com
>         +jinq0123 at 163.com>
>                          2006-11-09
>
>
>
>         _______________________________________________
>         python-chinese
>         Post: send python-chinese at lists.python.cn
>         +python-chinese at lists.python.cn>
>         Subscribe: send subscribe to
>         python-chinese-request at lists.python.cn
>         +python-chinese-request at lists.python.cn>
>         Unsubscribe: send unsubscribe to
>         python-chinese-request at lists.python.cn
>         +python-chinese-request at lists.python.cn>
>         Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
>     _______________________________________________
>     python-chinese
>     Post: send python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>
>     Subscribe: send subscribe to
>     python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     Unsubscribe: send unsubscribe to
>     python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
> #!/usr/bin/env/ python
> # -*- coding: GB2312 -*-
>
> # 测试
> class Person:
> '''Represents a person.'''
> population = 0
>
> def __init__(self, name):
> '''Initializing the person's data.'''
> self.name <http://self.name> = name
> print '(Initializing %s)' %self.name
> Person.population += 1
>
> def __del__(self):
> '''I am dying'''
> print '%s says bye.' %self.name
>
> Person.population -= 1
>
> if Person.population == 0:
> print 'I am the last one'
> else:
> print 'There are still %d person left' %Person.population
>
> def sayHi(self):
> '''Greeting by the person.
> really,that's all it does.'''
> print 'hello,I am %s' %self.name
>
> def howMany(self):
> '''print the current population.'''
> if Person.population == 1:
> print 'I am the only person here'
> else:
> print 'We have %d persons' %Person.population
>
> def main():
> iamzcy = Person('iamzcy')
> iamzcy.sayHi()
> iamzcy.howMany()
>
> sam = Person('sam')
> sam.sayHi()
> sam.howMany()
>
> iamzcy.sayHi()
> iamzcy.howMany ()
>
> main()
> 这样写就可以运行,结果为:
> (Initializing iamzcy)
> hello,I am iamzcy
> I am the only person here
> (Initializing sam)
> hello,I am sam
> We have 2 persons
> hello,I am iamzcy
> We have 2 persons
> iamzcy says bye.
> There are still 1 person left
> sam says bye.
> I am the last one
> 但如果将main函数中的代码移除到 main 函数之外,则会报错:
>
> (Initializing iamzcy)
> hello,I am iamzcy
> I am the only person here
> (Initializing sam)
> hello,I am sam
> We have 2 persons
> hello,I am iamzcy
> We have 2 persons
> sam says bye.
> There are still 1 person left
> iamzcy says bye.
> Exception exceptions.AttributeError: "'NoneType' object has no
> attribute 'population'" in > <__main__.Person instance at 0x00BF5D00>> ignored
>
> 看来应该是Python在回收对象时有问题。
>
>
> -- 
> 范洪滔
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

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

2006年11月10日 星期五 12:18

=?GB2312?B?u8aPqg==?= yellowfool在gmail.com
星期五 十一月 10 12:18:40 HKT 2006

ÕâÕæÊÇÒ»¸öÆæ¹ÖµÄÎÊÌâ
ÎÒ×Ðϸ¿´ÁËamingscµÄ½â´ð£¬²¢ÇÒÔÚwin2000+eclipse+pydev+python2.4.2£¬ÒÔ¼°linux 2.6.8.2.+python
2.3.5ÏÂ×öÁ˲âÊÔ¡£
ÔÚÕâÁ½¸ö»·¾³ÏÂnamespaceµÄ˳Ðò¾ùΪ£º
['Person', '__builtins__', '__doc__', '__file__', '__name__', 'iamzcy',
'sam']
ÔËÐйûÈ»³ö´í£¬µ«ÊǽÓÏÂÀ´µÄÊÂÇé¾ÍÓëamingscµÄ½âÊÍÓе㲻ͬÁË£¬ÎÒ¶ÔʵÀý¸ÄÃû£¬°Ñiamzcyͳһ¸ÄΪiam345,´ËʱnamespaceµÄ˳ÐòΪ£º
['Person', '__builtins__', '__doc__', '__file__', '__name__', 'iam345',
'sam']
ÎÞ±¨´í£¬µ«ÏÔʾ²»Õý³££¬×Ðϸ¹Û²ìһϣ¬³ÌÐòÔËÐе½iam345.__del__£¨£©Ö»ÔËÐе½"iam345 say bye"
½Ó׎«ÊµÀýÃû¸ÄΪia345£¬´ËʱnamespaceµÄ˳ÐòΪ£º
 ['Person', '__builtins__', '__doc__', '__file__', '__name__', 'ia345',
'sam']
ÎÞ±¨´í£¬Ò»ÇÐÕý³£
ÁíÍâ˵һ¾ä£ºPersonÕâ¸öÀà¿Ï¶¨ÊÇÔÚËüµÄʵÀý½áÊøÖ®ºó²Å»á±»ÊÍ·Å£¬²»ÐÅÄã°Ñ__del__£¨£©ÀïµÄPerson.population
,¸ÄΪself.__class__.population£¬²»»áÓÐÈκÎÎÊÌâ¡£ÏÖÔÚ×îΪÆæ¹ÖµÄÊÇPersonÕâ¸öÃû×ÖËüÊÇʲôʱ¼äÊͷŵģ¬ÓÖÓÐʲô¹æÔò£¿


2006/11/10, amingsc <amingsc在gmail.com>:
>
>
> ÄãÃÇÊÔÊÔ°ÑÀàÃû"Person"¸Ä³É"aerson"¿´¿´ÓÐûÓдíÎó£¿
> ûÁË°É£¿Óеã¹ÖŶ
> °´ÎÒµÄÀí½â£¬ÕâÒ²Õý³£
> ÔÚpython½ø³ÌÍ˳öµÄʱºò¿Ï¶¨»áÏú»ÙÆänamespace:
> ['__builtins__', '__doc__', '__name__', 'Person', 'iamzcy', 'sam']
> Ëü¿Ï¶¨ÓÐÒ»¶¨µÄÏú»Ù˳Ðò£¬Èç¹ûPersonÀàÔÚiamzcy¡¢sam֮ǰ±»Ïú»ÙµÄ»°ÄÇ
> ¿Ï¶¨ÓÐÎÊÌ⣬ËùÒÔ°ÑPerson¸Ä³Éaersonºó¾Í±ä³ÉÔÚiamzcy¡¢samÖ®ºóÏú»ÙÁË£¬
> ËùÒÔÒ²¾ÍûÓÐÎÊÌâÁË
> ¶ÔÓÚÔÚÄǶδúÂë·ÅÈëmainº¯ÊýÖÐÒ²ºÃÀí½â£¬ÒòΪiamzcy¡¢sam¿Ï¶¨ÔÚmain±»Ïú»Ù
> ֮ǰ±»Ïú»Ù£¬¶øPersonÊÇÓëmainÔÚÒ»¸öʱ¼ä¼¶Éϱ»Ïú»ÙµÄ£¬ËùÒÔ¡£¡£¡£
>
> Ò»°ãÀ´ËµclassÊDz»Ó¦¸ÃÔÚclass£­object֮ǰ±»Ïú»ÙµÄ£¬¿ÉÄÜpythonÉè¼ÆµÄʱºòû
> Óп¼Âǵ½
> Õâ¸öÎÊÌâ°É£¬Ò²¿ÉÄܹÊÒâÕâÑùÉè¼ÆµÄ£¬ÒòΪÅжÏclassÓëclass£­objectÒ²ÓÐʱ¼ä¿ª
> ÏúÂ
> ÔÙ˵±äÁ¿µÄÏú»ÙÒ²ºÜƵ·±£¬¶øÕâÖÖÒì³£ÔÚÕæʵµÄ¿ª·¢ÖÐÒ»°ãÓö²»Éϵģ¬ËùÒÔÓÐЩµÃ
> ²»³¥Ê§¡£
>
> Èç¹ûÄã·ÇµÃÕâôŪµÄ»°£¬ÄǾÍÏÔʽÏú»Ù°É
> del iamzcy
> del sam
> [del Person] ££ÕâÐв»ÓÃдµÄ£¬·´ÕýÔÚ×îºó²ÅÏú»ÙµÄ
>
> Fan Hongtao дµÀ:
> >
> > On 11/9/06, *nmweizi* <nmweizi在163.com nmweizi在163.com>> wrote:
> >
> >     python-chinese£¬ÄãºÃ
> >     ÊÔÁËÒ»ÏÂûÓÐʲô´óÎÊÌâ¡£Ö»ÊÇÔÚ×îºóÍƳöʱdel·½·¨Ìáʾ´íÎ󡣸ijÉÕâÑù
> >     ¾Í¿ÉÒÔÁË¡£
> >     class Person:
> >     '''Represents a person.'''
> >     population = 0
> >     def __init__(self,name):
> >     '''Initializing the person's data.'''
> >     self.name <http://self.name/> = name
> >     print '(Initializing %s)' %self.name
> >     Person.population += 1
> >     def __del__(self):
> >     '''I am dying'''
> >     print '%s says bye.' %self.name
> >
> >     if not Person:
> >     return
> >     Person.population -= 1
> >     if Person.population == 0:
> >     print 'I am the last one'
> >     else:
> >     print 'There are still %d person left' %Person.population
> >     def sayHi(self):
> >     '''Greeting by the person.
> >     really,that's all it does.'''
> >     print 'hello,I am %s' %self.name
> >     def howMany(self):
> >     '''print the current population.'''
> >     if Person.population == 1:
> >     print 'I am the only person here'
> >     else:
> >     print 'We have %d persons' %Person.population
> >     iamzcy = Person('iamzcy')
> >     iamzcy.sayHi()
> >     iamzcy.howMany()
> >     sam = Person('sam')
> >     sam.sayHi()
> >     sam.howMany()
> >     del sam
> >     iamzcy.sayHi()
> >     iamzcy.howMany()
> >     Ö´Ðнá¹ûÈçÏ£º
> >     (Initializing iamzcy)
> >     hello,I am iamzcy
> >     I am the only person here
> >     (Initializing sam)
> >     hello,I am sam
> >     We have 2 persons
> >     sam says bye.
> >     There are still 1 person left
> >     hello,I am iamzcy
> >     I am the only person here
> >     iamzcy says bye.
> >     nmweizi£¬nmweizi在163.com
> >     3Enmweizi在163.com
> %3C%21--AID_FROMADDRESS_END--%3E>
> >     2006-11-09
> >
> >         ----- Original Message -----
> >         *From: *Jin Qing jinq0123在163.com>
> >         *To: *python-chinese在lists.python.cn
> >         python-chinese在lists.python.cn>
> >         *Sent: *2006-11-09, 09:28:35
> >         *Subject: *Re: [python-chinese] (ÎÞÖ÷Ìâ)
> >
> >         iamzcyhit£¬ÄúºÃ£¡
> >
> >         ÓÐʲôÎÊÌ⣿ÎÒ¿´Ã»Ê²Ã´ÎÊÌâ¡£
> >
> >         ======== 2006-11-07 18:15:00 ÄúÔÚÀ´ÐÅÖÐдµÀ£º ========
> >
> >         ΪʲôÕâ¶Î´úÂëµÄÊä³ö×îºó¾¹È»ÓÐÎÊÌ⣿
> >         class Person:
> >         '''Represents a person.'''
> >         population = 0
> >
> >         def __init__(self,name):
> >         '''Initializing the person's data.'''
> >         self.name <http://self.name/> = name
> >         print '(Initializing %s)' %self.name
> >
> >         Person.population += 1
> >         def __del__(self):
> >         '''I am dying'''
> >         print '%s says bye.' %self.name
> >         Person.population -= 1
> >
> >         if Person.population == 0:
> >         print 'I am the last one'
> >         else:
> >         print 'There are still %d person left' %Person.population
> >         def sayHi(self):
> >         '''Greeting by the person.
> >         really,that's all it does.'''
> >         print 'hello,I am %s' %self.name
> >         def howMany(self):
> >         '''print the current population.'''
> >         if Person.population == 1:
> >         print 'I am the only person here'
> >         else:
> >         print 'We have %d persons' %Person.population
> >
> >         iamzcy = Person('iamzcy')
> >         iamzcy.sayHi()
> >         iamzcy.howMany()
> >
> >         sam = Person('sam')
> >         sam.sayHi()
> >         sam.howMany()
> >
> >         iamzcy.sayHi()
> >         iamzcy.howMany()
> >
> >
> >
> >
> >
> >         iamzcyhit
> >         2006-11-07
> >
> >         = = = = = = = = = = = = = = = = = = = = = =
> >         ÖÂ
> >         Àñ£¡
> >
> >         Jin Qing
> >          jinq0123在163.com
> >         +jinq0123在163.com>
> >         2006-11-09
> >
> >
> >
> >         _______________________________________________
> >         python-chinese
> >         Post: send python-chinese在lists.python.cn
> >         +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
> >         +python-chinese-request在lists.python.cn>
> >         Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> >
> >     _______________________________________________
> >     python-chinese
> >     Post: send python-chinese在lists.python.cn
> >     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
> >     python-chinese-request在lists.python.cn>
> >     Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> >
> > #!/usr/bin/env/ python
> > # -*- coding: GB2312 -*-
> >
> > # ²âÊÔ
> > class Person:
> > '''Represents a person.'''
> > population = 0
> >
> > def __init__(self, name):
> > '''Initializing the person's data.'''
> > self.name <http://self.name> = name
> > print '(Initializing %s)' %self.name
> > Person.population += 1
> >
> > def __del__(self):
> > '''I am dying'''
> > print '%s says bye.' %self.name
> >
> > Person.population -= 1
> >
> > if Person.population == 0:
> > print 'I am the last one'
> > else:
> > print 'There are still %d person left' %Person.population
> >
> > def sayHi(self):
> > '''Greeting by the person.
> > really,that's all it does.'''
> > print 'hello,I am %s' %self.name
> >
> > def howMany(self):
> > '''print the current population.'''
> > if Person.population == 1:
> > print 'I am the only person here'
> > else:
> > print 'We have %d persons' %Person.population
> >
> > def main():
> > iamzcy = Person('iamzcy')
> > iamzcy.sayHi()
> > iamzcy.howMany()
> >
> > sam = Person('sam')
> > sam.sayHi()
> > sam.howMany()
> >
> > iamzcy.sayHi()
> > iamzcy.howMany ()
> >
> > main()
> > ÕâÑùд¾Í¿ÉÒÔÔËÐУ¬½á¹ûΪ£º
> > (Initializing iamzcy)
> > hello,I am iamzcy
> > I am the only person here
> > (Initializing sam)
> > hello,I am sam
> > We have 2 persons
> > hello,I am iamzcy
> > We have 2 persons
> > iamzcy says bye.
> > There are still 1 person left
> > sam says bye.
> > I am the last one
> > µ«Èç¹û½«mainº¯ÊýÖеĴúÂëÒƳýµ½ main º¯ÊýÖ®Í⣬Ôò»á±¨´í£º
> >
> > (Initializing iamzcy)
> > hello,I am iamzcy
> > I am the only person here
> > (Initializing sam)
> > hello,I am sam
> > We have 2 persons
> > hello,I am iamzcy
> > We have 2 persons
> > sam says bye.
> > There are still 1 person left
> > iamzcy says bye.
> > Exception exceptions.AttributeError: "'NoneType' object has no
> > attribute 'population'" in > > <__main__.Person instance at 0x00BF5D00>> ignored
> >
> > ¿´À´Ó¦¸ÃÊÇPythonÔÚ»ØÊÕ¶ÔÏóʱÓÐÎÊÌâ¡£
> >
> >
> > --
> > ·¶ºéÌÏ
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > 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/20061110/6e85927b/attachment-0001.html 

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

2006年11月10日 星期五 13:59

amingsc amingsc在gmail.com
星期五 十一月 10 13:59:10 HKT 2006


»Æª дµÀ:
> ÕâÕæÊÇÒ»¸öÆæ¹ÖµÄÎÊÌâ
> ÎÒ×Ðϸ¿´ÁËamingscµÄ½â´ð£¬²¢ÇÒÔÚwin2000+ eclipse+pydev+python2.4.2£¬ÒÔ
> ¼°linux 2.6.8.2.+python 2.3.5ÏÂ×öÁ˲âÊÔ¡£
> ÔÚÕâÁ½¸ö»·¾³ÏÂnamespaceµÄ˳Ðò¾ùΪ£º
> ['Person', '__builtins__', '__doc__', '__file__', '__name__',
> 'iamzcy', 'sam']
> ÔËÐйûÈ»³ö´í£¬µ«ÊǽÓÏÂÀ´µÄÊÂÇé¾ÍÓëamingscµÄ½âÊÍÓе㲻ͬÁË£¬ÎÒ¶ÔʵÀý¸Ä
> Ãû£¬°Ñiamzcyͳһ¸ÄΪiam345,´Ëʱ namespaceµÄ˳ÐòΪ£º
> ['Person', '__builtins__', '__doc__', '__file__', '__name__',
> 'iam345', 'sam']
> ÎÞ±¨´í£¬µ«ÏÔʾ²»Õý³££¬×Ðϸ¹Û²ìһϣ¬³ÌÐòÔËÐе½iam345.__del__£¨£©Ö»ÔËÐÐ
> µ½"iam345 say bye"
> ½Ó׎«ÊµÀýÃû¸ÄΪia345£¬´ËʱnamespaceµÄ˳ÐòΪ£º
> ['Person', '__builtins__', '__doc__', '__file__', '__name__', 'ia345',
> 'sam']
> ÎÞ±¨´í£¬Ò»ÇÐÕý³£
ÕâÀïµÄ˳Ðò²»ÊÇdirËùÏÔʾ³öÀ´µÄ×Öĸ˳Ðò£¬¶øÊÇdictÄÚ²¿µÄhashË÷ÒýµÄ˳Ðò£¬Òò
ΪnamespaceÖеÄËùÓжÔÏó¶¼ÊÇÒÔdictµÄ·½Ê½±£´æµÄ£¬ÎÒ²ÂÏëÓ¦¸ÃÊÇÕâÑùʵÏֵģ¬
Äã¿ÉÒÔÈ¥Éè¼Æ¸öʵÑéÊÔÊÔ
> ÁíÍâ˵һ¾ä£ºPersonÕâ¸öÀà¿Ï¶¨ÊÇÔÚËüµÄʵÀý½áÊøÖ®ºó²Å»á±»ÊÍ·Å£¬²»ÐÅÄã°Ñ
> __del__£¨£©ÀïµÄ Person.population,¸ÄΪself.__class__.population£¬²»»á
> ÓÐÈκÎÎÊÌâ¡£ÏÖÔÚ×îΪÆæ¹ÖµÄÊÇPersonÕâ¸öÃû×ÖËüÊÇʲôʱ¼äÊͷŵģ¬ÓÖÓÐʲô
> ¹æÔò£¿
>
¹þ¹þ£¬ÎÒÊÇ˵µÃ²»¶Ô£¬¸üÕýÏ£¬ÃâµÃÎóµ¼ÈË£º
ÕâÀïPersonÔÚnamespaceÀïÃæ½ö½öÊÇÒ»¸ökey£¨¶ÔclassµÄÒ»¸öÒýÓã©£¬Ï൱ÓÚÖ¸Õë
Ö®ÀàµÄ¶«Î÷£¬¶øself.__class__ÊÇ PersonµÄ´úÀí£¬
ËùÒÔdel PersonÏ൱ÓÚÊÇɾ³ýÁËÒ»¸öÖ¸Õ루ÕâÀïÊÇÒýÓã©£¬¶øPersonËùÖ¸ÏòµÄÄǸö
class»¹ÊÇ´æÔڵģ¬µ«ÊÇÎÒÃÇÒѾ­²»ÄÜÔÙͨ¹ýPersonÀ´·ÃÎÊ classÀ²£¬ËùÒԲű¨´í
µÄ£¬Äã¸Ä³É¸ÄΪself.__class__.populationºóÒѾ­²»Í¨¹ýPersonÀ´ÒýÓÃclassÁË£¬
ËùÒÔûÓб¨´íµÄ¡£µ±È»Õâ¸öclassµÄÊͷŲ»ÊÇÓÉÎÒÃDzÙ×ݵģ¬ËûÍêÈ«ÊÇpython¹ÜÀí
µÄ£¬µ±Ã»ÓжÔclassµÄÈκÎÒýÓõÄʱºòpython¾Í»áÔÚÊʵ±µÄʱºòÏú»Ù¡£
> 2006/11/10, amingsc <amingsc at gmail.com amingsc at gmail.com>>:
>
>
>     ÄãÃÇÊÔÊÔ°ÑÀàÃû"Person"¸Ä³É"aerson"¿´¿´ÓÐûÓдíÎó£¿
>     ûÁË°É£¿Óеã¹ÖŶ
>     °´ÎÒµÄÀí½â£¬ÕâÒ²Õý³£
>     ÔÚpython½ø³ÌÍ˳öµÄʱºò¿Ï¶¨»áÏú»ÙÆänamespace:
>     ['__builtins__', '__doc__', '__name__', 'Person', 'iamzcy', 'sam']
>     Ëü¿Ï¶¨ÓÐÒ»¶¨µÄÏú»Ù˳Ðò£¬Èç¹ûPersonÀàÔÚiamzcy¡¢sam֮ǰ±»Ïú»ÙµÄ»°ÄÇ
>     ¿Ï¶¨ÓÐÎÊÌ⣬ËùÒÔ°ÑPerson¸Ä³Éaersonºó¾Í±ä³ÉÔÚiamzcy¡¢samÖ®ºóÏú»ÙÁË£¬
>     ËùÒÔÒ²¾ÍûÓÐÎÊÌâÁË
>     ¶ÔÓÚÔÚÄǶδúÂë·ÅÈëmainº¯ÊýÖÐÒ²ºÃÀí½â£¬ÒòΪiamzcy¡¢sam¿Ï¶¨ÔÚmain±»Ïú»Ù
>     ֮ǰ±»Ïú»Ù£¬¶øPersonÊÇÓëmainÔÚÒ»¸öʱ¼ä¼¶Éϱ»Ïú»ÙµÄ£¬ËùÒÔ¡£¡£¡£
>
>     Ò»°ãÀ´ËµclassÊDz»Ó¦¸ÃÔÚclass£­object֮ǰ±»Ïú»ÙµÄ£¬¿ÉÄÜpythonÉè¼ÆµÄ
>     ʱºòû
>     Óп¼Âǵ½
>     Õâ¸öÎÊÌâ°É£¬Ò²¿ÉÄܹÊÒâÕâÑùÉè¼ÆµÄ£¬ÒòΪÅжÏclassÓëclass£­objectÒ²ÓÐ
>     ʱ¼ä¿ª
>     ÏúÂ
>     ÔÙ˵±äÁ¿µÄÏú»ÙÒ²ºÜƵ·±£¬¶øÕâÖÖÒì³£ÔÚÕæʵµÄ¿ª·¢ÖÐÒ»°ãÓö²»Éϵģ¬ËùÒÔ
>     ÓÐЩµÃ
>     ²»³¥Ê§¡£
>
>     Èç¹ûÄã·ÇµÃÕâôŪµÄ»°£¬ÄǾÍÏÔʽÏú»Ù°É
>     del iamzcy
>     del sam
>     [del Person] ££ÕâÐв»ÓÃдµÄ£¬·´ÕýÔÚ×îºó²ÅÏú»ÙµÄ
>
>     Fan Hongtao дµÀ:
>     >
>     > On 11/9/06, *nmweizi* <nmweizi at 163.com nmweizi at 163.com>
>     nmweizi at 163.com nmweizi at 163.com>>> wrote:
>     >
>     > python-chinese£¬ÄãºÃ
>     > ÊÔÁËÒ»ÏÂûÓÐʲô´óÎÊÌâ¡£Ö»ÊÇÔÚ×îºóÍƳöʱdel·½·¨Ìáʾ´íÎ󡣸ijÉÕâÑù
>     > ¾Í¿ÉÒÔÁË¡£
>     > class Person:
>     > '''Represents a person.'''
>     > population = 0
>     > def __init__(self,name):
>     > '''Initializing the person's data.'''
>     > self.name <http://self.name> <http://self.name/> = name
>     > print '(Initializing %s)' %self.name
>     > Person.population += 1
>     > def __del__(self):
>     > '''I am dying'''
>     > print '%s says bye.' %self.name
>     >
>     > if not Person:
>     > return
>     > Person.population -= 1
>     > if Person.population == 0:
>     > print 'I am the last one'
>     > else:
>     > print 'There are still %d person left' %Person.population
>     > def sayHi(self):
>     > '''Greeting by the person.
>     > really,that's all it does.'''
>     > print 'hello,I am %s' %self.name
>     > def howMany(self):
>     > '''print the current population.'''
>     > if Person.population == 1:
>     > print 'I am the only person here'
>     > else:
>     > print 'We have %d persons' %Person.population
>     > iamzcy = Person('iamzcy')
>     > iamzcy.sayHi()
>     > iamzcy.howMany()
>     > sam = Person('sam')
>     > sam.sayHi()
>     > sam.howMany()
>     > del sam
>     > iamzcy.sayHi ()
>     > iamzcy.howMany()
>     > Ö´Ðнá¹ûÈçÏ£º
>     > (Initializing iamzcy)
>     > hello,I am iamzcy
>     > I am the only person here
>     > (Initializing sam)
>     > hello,I am sam
>     > We have 2 persons
>     > sam says bye.
>     > There are still 1 person left
>     > hello,I am iamzcy
>     > I am the only person here
>     > iamzcy says bye.
>     > nmweizi£¬nmweizi at 163.com nmweizi at 163.com>
>     >
>     3Enmweizi at 163.com%3C%21--AID_FROMADDRESS_END--%3E>
>     > 2006-11-09
>     >
>     > ----- Original Message -----
>     > *From: *Jin Qing jinq0123 at 163.com
>     jinq0123 at 163.com>>
>     > *To: *python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>
>     > python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>>
>     > *Sent: *2006-11-09, 09:28:35
>     > *Subject: *Re: [python-chinese] (ÎÞÖ÷Ìâ)
>     >
>     > iamzcyhit£¬ÄúºÃ£¡
>     >
>     > ÓÐʲôÎÊÌ⣿ÎÒ¿´Ã»Ê²Ã´ÎÊÌâ¡£¡¡¡¡
>     >
>     > ======== 2006-11-07 18:15:00 ÄúÔÚÀ´ÐÅÖÐдµÀ£º ========
>     >
>     > ΪʲôÕâ¶Î´úÂëµÄÊä³ö×îºó¾¹È»ÓÐÎÊÌ⣿
>     > class Person:
>     > '''Represents a person.'''
>     > population = 0
>     >
>     > def __init__(self,name):
>     > '''Initializing the person's data.'''
>     > self.name <http://self.name> <http://self.name/> = name
>     > print '(Initializing %s)' %self.name
>     >
>     > Person.population += 1
>     > def __del__(self):
>     > '''I am dying'''
>     > print '%s says bye.' %self.name
>     > Person.population -= 1
>     >
>     > if Person.population == 0:
>     > print 'I am the last one'
>     > else:
>     > print 'There are still %d person left' %Person.population
>     > def sayHi(self):
>     > '''Greeting by the person.
>     > really,that's all it does.'''
>     > print 'hello,I am %s' %self.name
>     > def howMany(self):
>     > '''print the current population.'''
>     > if Person.population == 1:
>     > print 'I am the only person here'
>     > else:
>     > print 'We have %d persons' %Person.population
>     >
>     > iamzcy = Person('iamzcy')
>     > iamzcy.sayHi()
>     > iamzcy.howMany()
>     >
>     > sam = Person('sam')
>     > sam.sayHi()
>     > sam.howMany()
>     >
>     > iamzcy.sayHi()
>     > iamzcy.howMany()
>     >
>     >
>     >
>     >
>     >
>     > iamzcyhit
>     > 2006-11-07
>     >
>     > = = = = = = = = = = = = = = = = = = = = = =
>     > ÖÂ
>     > Àñ£¡
>     >
>     > Jin Qing
>     > jinq0123 at 163.com jinq0123 at 163.com>
>     > +jinq0123 at 163.com +jinq0123 at 163.com>>
>     > 2006-11-09
>     >
>     >
>     >
>     > _______________________________________________
>     > python-chinese
>     > Post: send python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>
>     > +python-chinese at lists.python.cn
>     +python-chinese at lists.python.cn>>
>     > Subscribe: send subscribe to
>     > python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     > < mailto:+python-chinese-request at lists.python.cn
>     +python-chinese-request at lists.python.cn>>
>     > Unsubscribe: send unsubscribe to
>     > python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     > +python-chinese-request at lists.python.cn
>     +python-chinese-request at lists.python.cn>>
>     > Detail Info: http://python.cn/mailman/listinfo/python-chinese
>     >
>     >
>     > _______________________________________________
>     > python-chinese
>     > Post: send python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>
>     > python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>>
>     > Subscribe: send subscribe to
>     > python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     > python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>>
>     > Unsubscribe: send unsubscribe to
>     > python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     > python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>>
>     > Detail Info: http://python.cn/mailman/listinfo/python-chinese
>     >
>     >
>     > #!/usr/bin/env/ python
>     > #¡¡-*- coding: GB2312 -*-
>     >
>     > # ²âÊÔ
>     > class Person:
>     > '''Represents a person.'''
>     > population = 0
>     >
>     > def __init__(self, name):
>     > '''Initializing the person's data.'''
>     > self.name <http://self.name> <http://self.name> = name
>     > print '(Initializing %s)' %self.name
>     > Person.population += 1
>     >
>     > def __del__(self):
>     > '''I am dying'''
>     > print '%s says bye.' %self.name
>     >
>     > Person.population -= 1
>     >
>     > if Person.population == 0:
>     > print 'I am the last one'
>     > else:
>     > print 'There are still %d person left' %Person.population
>     >
>     > def sayHi(self):
>     > '''Greeting by the person.
>     > really,that's all it does.'''
>     > print 'hello,I am %s' %self.name
>     >
>     > def howMany(self):
>     > '''print the current population.'''
>     > if Person.population == 1:
>     > print 'I am the only person here'
>     > else:
>     > print 'We have %d persons' %Person.population
>     >
>     > def main():
>     > iamzcy = Person('iamzcy')
>     > iamzcy.sayHi()
>     > iamzcy.howMany ()
>     >
>     > sam = Person('sam')
>     > sam.sayHi()
>     > sam.howMany()
>     >
>     > iamzcy.sayHi()
>     > iamzcy.howMany ()
>     >
>     > main()
>     > ÕâÑùд¾Í¿ÉÒÔÔËÐУ¬½á¹ûΪ£º
>     > (Initializing iamzcy)
>     > hello,I am iamzcy
>     > I am the only person here
>     > (Initializing sam)
>     > hello,I am sam
>     > We have 2 persons
>     > hello,I am iamzcy
>     > We have 2 persons
>     > iamzcy says bye.
>     > There are still 1 person left
>     > sam says bye.
>     > I am the last one
>     > µ«Èç¹û½«mainº¯ÊýÖеĴúÂëÒƳýµ½ main º¯ÊýÖ®Í⣬Ôò»á±¨´í£º
>     >
>     > (Initializing iamzcy)
>     > hello,I am iamzcy
>     > I am the only person here
>     > (Initializing sam)
>     > hello,I am sam
>     > We have 2 persons
>     > hello,I am iamzcy
>     > We have 2 persons
>     > sam says bye.
>     > There are still 1 person left
>     > iamzcy says bye.
>     > Exception exceptions.AttributeError: "'NoneType' object has no
>     > attribute 'population'" in >     > <__main__.Person instance at 0x00BF5D00>> ignored
>     >
>     > ¿´À´Ó¦¸ÃÊÇPythonÔÚ»ØÊÕ¶ÔÏóʱÓÐÎÊÌâ¡£
>     >
>     >
>     > --
>     > ·¶ºéÌÏ
>     >
>     >
>     ------------------------------------------------------------------------
>     >
>     > _______________________________________________
>     > python-chinese
>     > Post: send python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>
>     > Subscribe: send subscribe to
>     python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     > Unsubscribe: send unsubscribe to
>     python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     > Detail Info: http://python.cn/mailman/listinfo/python-chinese
>     _______________________________________________
>     python-chinese
>     Post: send python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>
>     Subscribe: send subscribe to
>     python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     Unsubscribe: send unsubscribe to
>     python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     Detail Info: http://python.cn/mailman/listinfo/python-chinese
>     <http://python.cn/mailman/listinfo/python-chinese>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

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

2006年11月10日 星期五 15:36

=?GB2312?B?u8aPqg==?= yellowfool在gmail.com
星期五 十一月 10 15:36:13 HKT 2006

ÔÚ06-11-10£¬amingsc <amingsc在gmail.com> дµÀ£º

> ÕâÀïµÄ˳Ðò²»ÊÇdirËùÏÔʾ³öÀ´µÄ×Öĸ˳Ðò£¬¶øÊÇdictÄÚ²¿µÄhashË÷ÒýµÄ˳Ðò£¬Òò
> ΪnamespaceÖеÄËùÓжÔÏó¶¼ÊÇÒÔdictµÄ·½Ê½±£´æµÄ£¬ÎÒ²ÂÏëÓ¦¸ÃÊÇÕâÑùʵÏֵģ¬
> Äã¿ÉÒÔÈ¥Éè¼Æ¸öʵÑéÊÔÊÔ


лл*amingsc*
£¬Ô­À´ÊÇÕâÑù£¬¿ÉÊDz»ÖªµÀÔõô²ÅÄÜ¿´µÃµ½Êµ¼ÊµÄ˳Ðò£¬²»¹ýÕâÑùÇî×·²»ÉáËƺõҲûʲô±ØÒª¡£Ä£¿éÖеÄ__dict__Ó¦¸Ã´æ·ÅÄ£¿éÃüÃû¿Õ¼ä°É£¬È´ÊÇÔõôÄÜ¿´µ½ÄØ£¿



> > ÁíÍâ˵һ¾ä£ºPersonÕâ¸öÀà¿Ï¶¨ÊÇÔÚËüµÄʵÀý½áÊøÖ®ºó²Å»á±»ÊÍ·Å£¬²»ÐÅÄã°Ñ
> > __del__£¨£©ÀïµÄ Person.population,¸ÄΪself.__class__.population£¬²»»á
> > ÓÐÈκÎÎÊÌâ¡£ÏÖÔÚ×îΪÆæ¹ÖµÄÊÇPersonÕâ¸öÃû×ÖËüÊÇʲôʱ¼äÊͷŵģ¬ÓÖÓÐʲô
> > ¹æÔò£¿
> >
> ¹þ¹þ£¬ÎÒÊÇ˵µÃ²»¶Ô£¬¸üÕýÏ£¬ÃâµÃÎóµ¼ÈË£º
> ÕâÀïPersonÔÚnamespaceÀïÃæ½ö½öÊÇÒ»¸ökey£¨¶ÔclassµÄÒ»¸öÒýÓã©£¬Ï൱ÓÚÖ¸Õë
> Ö®ÀàµÄ¶«Î÷£¬¶øself.__class__ÊÇ PersonµÄ´úÀí£¬
> ËùÒÔdel PersonÏ൱ÓÚÊÇɾ³ýÁËÒ»¸öÖ¸Õ루ÕâÀïÊÇÒýÓã©£¬¶øPersonËùÖ¸ÏòµÄÄǸö
> class»¹ÊÇ´æÔڵģ¬µ«ÊÇÎÒÃÇÒѾ­²»ÄÜÔÙͨ¹ýPersonÀ´·ÃÎÊ classÀ²£¬ËùÒԲű¨´í
> µÄ£¬Äã¸Ä³É¸ÄΪself.__class__.populationºóÒѾ­²»Í¨¹ýPersonÀ´ÒýÓÃclassÁË£¬
> ËùÒÔûÓб¨´íµÄ¡£µ±È»Õâ¸öclassµÄÊͷŲ»ÊÇÓÉÎÒÃDzÙ×ݵģ¬ËûÍêÈ«ÊÇpython¹ÜÀí
> µÄ£¬µ±Ã»ÓжÔclassµÄÈκÎÒýÓõÄʱºòpython¾Í»áÔÚÊʵ±µÄʱºòÏú»Ù¡£
> > 2006/11/10, amingsc <amingsc在gmail.com amingsc在gmail.com>>:
> >
> >
> >     ÄãÃÇÊÔÊÔ°ÑÀàÃû"Person"¸Ä³É"aerson"¿´¿´ÓÐûÓдíÎó£¿
> >     ûÁË°É£¿Óеã¹ÖŶ
> >     °´ÎÒµÄÀí½â£¬ÕâÒ²Õý³£
> >     ÔÚpython½ø³ÌÍ˳öµÄʱºò¿Ï¶¨»áÏú»ÙÆänamespace:
> >     ['__builtins__', '__doc__', '__name__', 'Person', 'iamzcy', 'sam']
> >     Ëü¿Ï¶¨ÓÐÒ»¶¨µÄÏú»Ù˳Ðò£¬Èç¹ûPersonÀàÔÚiamzcy¡¢sam֮ǰ±»Ïú»ÙµÄ»°ÄÇ
> >     ¿Ï¶¨ÓÐÎÊÌ⣬ËùÒÔ°ÑPerson¸Ä³Éaersonºó¾Í±ä³ÉÔÚiamzcy¡¢samÖ®ºóÏú»ÙÁË£¬
> >     ËùÒÔÒ²¾ÍûÓÐÎÊÌâÁË
> >     ¶ÔÓÚÔÚÄǶδúÂë·ÅÈëmainº¯ÊýÖÐÒ²ºÃÀí½â£¬ÒòΪiamzcy¡¢sam¿Ï¶¨ÔÚmain±»Ïú»Ù
> >     ֮ǰ±»Ïú»Ù£¬¶øPersonÊÇÓëmainÔÚÒ»¸öʱ¼ä¼¶Éϱ»Ïú»ÙµÄ£¬ËùÒÔ¡£¡£¡£
> >
> >     Ò»°ãÀ´ËµclassÊDz»Ó¦¸ÃÔÚclass£­object֮ǰ±»Ïú»ÙµÄ£¬¿ÉÄÜpythonÉè¼ÆµÄ
> >     ʱºòû
> >     Óп¼Âǵ½
> >     Õâ¸öÎÊÌâ°É£¬Ò²¿ÉÄܹÊÒâÕâÑùÉè¼ÆµÄ£¬ÒòΪÅжÏclassÓëclass£­objectÒ²ÓÐ
> >     ʱ¼ä¿ª
> >     ÏúÂ
> >     ÔÙ˵±äÁ¿µÄÏú»ÙÒ²ºÜƵ·±£¬¶øÕâÖÖÒì³£ÔÚÕæʵµÄ¿ª·¢ÖÐÒ»°ãÓö²»Éϵģ¬ËùÒÔ
> >     ÓÐЩµÃ
> >     ²»³¥Ê§¡£
> >
> >     Èç¹ûÄã·ÇµÃÕâôŪµÄ»°£¬ÄǾÍÏÔʽÏú»Ù°É
> >     del iamzcy
> >     del sam
> >     [del Person] ££ÕâÐв»ÓÃдµÄ£¬·´ÕýÔÚ×îºó²ÅÏú»ÙµÄ
> >
> >     Fan Hongtao дµÀ:
> >     >
> >     > On 11/9/06, *nmweizi* <nmweizi在163.com nmweizi在163.com>
> >     nmweizi在163.com nmweizi在163.com>>> wrote:
> >     >
> >     > python-chinese£¬ÄãºÃ
> >     > ÊÔÁËÒ»ÏÂûÓÐʲô´óÎÊÌâ¡£Ö»ÊÇÔÚ×îºóÍƳöʱdel·½·¨Ìáʾ´íÎ󡣸ijÉÕâÑù
> >     > ¾Í¿ÉÒÔÁË¡£
> >     > class Person:
> >     > '''Represents a person.'''
> >     > population = 0
> >     > def __init__(self,name):
> >     > '''Initializing the person's data.'''
> >     > self.name <http://self.name> <http://self.name/> = name
> >     > print '(Initializing %s)' %self.name
> >     > Person.population += 1
> >     > def __del__(self):
> >     > '''I am dying'''
> >     > print '%s says bye.' %self.name
> >     >
> >     > if not Person:
> >     > return
> >     > Person.population -= 1
> >     > if Person.population == 0:
> >     > print 'I am the last one'
> >     > else:
> >     > print 'There are still %d person left' %Person.population
> >     > def sayHi(self):
> >     > '''Greeting by the person.
> >     > really,that's all it does.'''
> >     > print 'hello,I am %s' %self.name
> >     > def howMany(self):
> >     > '''print the current population.'''
> >     > if Person.population == 1:
> >     > print 'I am the only person here'
> >     > else:
> >     > print 'We have %d persons' %Person.population
> >     > iamzcy = Person('iamzcy')
> >     > iamzcy.sayHi()
> >     > iamzcy.howMany()
> >     > sam = Person('sam')
> >     > sam.sayHi()
> >     > sam.howMany()
> >     > del sam
> >     > iamzcy.sayHi ()
> >     > iamzcy.howMany()
> >     > Ö´Ðнá¹ûÈçÏ£º
> >     > (Initializing iamzcy)
> >     > hello,I am iamzcy
> >     > I am the only person here
> >     > (Initializing sam)
> >     > hello,I am sam
> >     > We have 2 persons
> >     > sam says bye.
> >     > There are still 1 person left
> >     > hello,I am iamzcy
> >     > I am the only person here
> >     > iamzcy says bye.
> >     > nmweizi£¬nmweizi在163.com nmweizi在163.com>
> >     >
> >     3Enmweizi在163.com
> %3C%21--AID_FROMADDRESS_END--%3E>
> >     > 2006-11-09
> >     >
> >     > ----- Original Message -----
> >     > *From: *Jin Qing jinq0123在163.com
> >     jinq0123在163.com>>
> >     > *To: *python-chinese在lists.python.cn
> >     python-chinese在lists.python.cn>
> >     > python-chinese在lists.python.cn
> >     python-chinese在lists.python.cn>>
> >     > *Sent: *2006-11-09, 09:28:35
> >     > *Subject: *Re: [python-chinese] (ÎÞÖ÷Ìâ)
> >     >
> >     > iamzcyhit£¬ÄúºÃ£¡
> >     >
> >     > ÓÐʲôÎÊÌ⣿ÎÒ¿´Ã»Ê²Ã´ÎÊÌâ¡£
> >     >
> >     > ======== 2006-11-07 18:15:00 ÄúÔÚÀ´ÐÅÖÐдµÀ£º ========
> >     >
> >     > ΪʲôÕâ¶Î´úÂëµÄÊä³ö×îºó¾¹È»ÓÐÎÊÌ⣿
> >     > class Person:
> >     > '''Represents a person.'''
> >     > population = 0
> >     >
> >     > def __init__(self,name):
> >     > '''Initializing the person's data.'''
> >     > self.name <http://self.name> <http://self.name/> = name
> >     > print '(Initializing %s)' %self.name
> >     >
> >     > Person.population += 1
> >     > def __del__(self):
> >     > '''I am dying'''
> >     > print '%s says bye.' %self.name
> >     > Person.population -= 1
> >     >
> >     > if Person.population == 0:
> >     > print 'I am the last one'
> >     > else:
> >     > print 'There are still %d person left' %Person.population
> >     > def sayHi(self):
> >     > '''Greeting by the person.
> >     > really,that's all it does.'''
> >     > print 'hello,I am %s' %self.name
> >     > def howMany(self):
> >     > '''print the current population.'''
> >     > if Person.population == 1:
> >     > print 'I am the only person here'
> >     > else:
> >     > print 'We have %d persons' %Person.population
> >     >
> >     > iamzcy = Person('iamzcy')
> >     > iamzcy.sayHi()
> >     > iamzcy.howMany()
> >     >
> >     > sam = Person('sam')
> >     > sam.sayHi()
> >     > sam.howMany()
> >     >
> >     > iamzcy.sayHi()
> >     > iamzcy.howMany()
> >     >
> >     >
> >     >
> >     >
> >     >
> >     > iamzcyhit
> >     > 2006-11-07
> >     >
> >     > = = = = = = = = = = = = = = = = = = = = = =
> >     > ÖÂ
> >     > Àñ£¡
> >     >
> >     > Jin Qing
> >     > jinq0123在163.com jinq0123在163.com>
> >     > +jinq0123在163.com +jinq0123在163.com>>
> >     > 2006-11-09
> >     >
> >     >
> >     >
> >     > _______________________________________________
> >     > python-chinese
> >     > Post: send python-chinese在lists.python.cn
> >     python-chinese在lists.python.cn>
> >     > +python-chinese在lists.python.cn
> >     +python-chinese在lists.python.cn>>
> >     > Subscribe: send subscribe to
> >     > python-chinese-request在lists.python.cn
> >     python-chinese-request在lists.python.cn>
> >     > < mailto:+python-chinese-request在lists.python.cn
> >     +python-chinese-request在lists.python.cn>>
> >     > Unsubscribe: send unsubscribe to
> >     > python-chinese-request在lists.python.cn
> >     python-chinese-request在lists.python.cn>
> >     > +python-chinese-request在lists.python.cn
> >     +python-chinese-request在lists.python.cn>>
> >     > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >     >
> >     >
> >     > _______________________________________________
> >     > python-chinese
> >     > Post: send python-chinese在lists.python.cn
> >     python-chinese在lists.python.cn>
> >     > python-chinese在lists.python.cn
> >     python-chinese在lists.python.cn>>
> >     > Subscribe: send subscribe to
> >     > python-chinese-request在lists.python.cn
> >     python-chinese-request在lists.python.cn>
> >     > python-chinese-request在lists.python.cn
> >     python-chinese-request在lists.python.cn>>
> >     > Unsubscribe: send unsubscribe to
> >     > python-chinese-request在lists.python.cn
> >     python-chinese-request在lists.python.cn>
> >     > python-chinese-request在lists.python.cn
> >     python-chinese-request在lists.python.cn>>
> >     > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >     >
> >     >
> >     > #!/usr/bin/env/ python
> >     > # -*- coding: GB2312 -*-
> >     >
> >     > # ²âÊÔ
> >     > class Person:
> >     > '''Represents a person.'''
> >     > population = 0
> >     >
> >     > def __init__(self, name):
> >     > '''Initializing the person's data.'''
> >     > self.name <http://self.name> <http://self.name> = name
> >     > print '(Initializing %s)' %self.name
> >     > Person.population += 1
> >     >
> >     > def __del__(self):
> >     > '''I am dying'''
> >     > print '%s says bye.' %self.name
> >     >
> >     > Person.population -= 1
> >     >
> >     > if Person.population == 0:
> >     > print 'I am the last one'
> >     > else:
> >     > print 'There are still %d person left' %Person.population
> >     >
> >     > def sayHi(self):
> >     > '''Greeting by the person.
> >     > really,that's all it does.'''
> >     > print 'hello,I am %s' %self.name
> >     >
> >     > def howMany(self):
> >     > '''print the current population.'''
> >     > if Person.population == 1:
> >     > print 'I am the only person here'
> >     > else:
> >     > print 'We have %d persons' %Person.population
> >     >
> >     > def main():
> >     > iamzcy = Person('iamzcy')
> >     > iamzcy.sayHi()
> >     > iamzcy.howMany ()
> >     >
> >     > sam = Person('sam')
> >     > sam.sayHi()
> >     > sam.howMany()
> >     >
> >     > iamzcy.sayHi()
> >     > iamzcy.howMany ()
> >     >
> >     > main()
> >     > ÕâÑùд¾Í¿ÉÒÔÔËÐУ¬½á¹ûΪ£º
> >     > (Initializing iamzcy)
> >     > hello,I am iamzcy
> >     > I am the only person here
> >     > (Initializing sam)
> >     > hello,I am sam
> >     > We have 2 persons
> >     > hello,I am iamzcy
> >     > We have 2 persons
> >     > iamzcy says bye.
> >     > There are still 1 person left
> >     > sam says bye.
> >     > I am the last one
> >     > µ«Èç¹û½«mainº¯ÊýÖеĴúÂëÒƳýµ½ main º¯ÊýÖ®Í⣬Ôò»á±¨´í£º
> >     >
> >     > (Initializing iamzcy)
> >     > hello,I am iamzcy
> >     > I am the only person here
> >     > (Initializing sam)
> >     > hello,I am sam
> >     > We have 2 persons
> >     > hello,I am iamzcy
> >     > We have 2 persons
> >     > sam says bye.
> >     > There are still 1 person left
> >     > iamzcy says bye.
> >     > Exception exceptions.AttributeError: "'NoneType' object has no
> >     > attribute 'population'" in > >     > <__main__.Person instance at 0x00BF5D00>> ignored
> >     >
> >     > ¿´À´Ó¦¸ÃÊÇPythonÔÚ»ØÊÕ¶ÔÏóʱÓÐÎÊÌâ¡£
> >     >
> >     >
> >     > --
> >     > ·¶ºéÌÏ
> >     >
> >     >
> >
> ------------------------------------------------------------------------
> >     >
> >     > _______________________________________________
> >     > python-chinese
> >     > Post: send python-chinese在lists.python.cn
> >     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
> >     python-chinese-request在lists.python.cn>
> >     > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >     _______________________________________________
> >     python-chinese
> >     Post: send python-chinese在lists.python.cn
> >     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
> >     python-chinese-request在lists.python.cn>
> >     Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >     <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
>
>
> _______________________________________________
> 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/20061110/abaf26bc/attachment.html 

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

2006年11月10日 星期五 16:13

amingsc amingsc在gmail.com
星期五 十一月 10 16:13:07 HKT 2006


»Æª дµÀ:
>
> ÔÚ06-11-10£¬*amingsc* <amingsc at gmail.com amingsc at gmail.com>>
> дµÀ£º
>
>     ÕâÀïµÄ˳Ðò²»ÊÇdirËùÏÔʾ³öÀ´µÄ×Öĸ˳Ðò£¬¶øÊÇdictÄÚ²¿µÄhashË÷ÒýµÄ˳
>     Ðò£¬Òò
>     ΪnamespaceÖеÄËùÓжÔÏó¶¼ÊÇÒÔdictµÄ·½Ê½±£´æµÄ£¬ÎÒ²ÂÏëÓ¦¸ÃÊÇÕâÑùʵ
>     Ïֵģ¬
>     Äã¿ÉÒÔÈ¥Éè¼Æ¸öʵÑéÊÔÊÔ
>
> лл*amingsc*£¬Ô­À´ÊÇÕâÑù£¬¿ÉÊDz»ÖªµÀÔõô²ÅÄÜ¿´µÃµ½Êµ¼ÊµÄ˳Ðò£¬²»¹ýÕâ
> ÑùÇî×·²»ÉáËƺõҲûʲô±ØÒª¡£Ä£¿éÖеÄ__dict__Ó¦¸Ã´æ·ÅÄ£¿éÃüÃû¿Õ¼ä°É£¬È´
> ÊÇÔõôÄÜ¿´µ½ÄØ£¿
>
²»ÖªµÀ__dict__ÊǸÉÂïµÄ£¬²»¹ýºÃÏñ__dict__ÀïÃæ±£´æµÄ¶ÔÏó¶¼ÊÇ¿ÉÒÔÔÚÍâÃæ·ÃÎʵÄ
ÔËÐÐÒ»ÏÂÏÂÃæµÄÀý×Ó¿ÉÒÔ¿´³öÆ京Ò壺
def f(a):
*****f.b = a
*****c = a+1
*****print locals()

f(2)
f.__dict__
f.d=3
f.__dict__
ÉÏÃælocals£¨£©ÔòÏÔʾÁËnamespace£¬ÄÇÊǼ´Ê±µÄ
¶ø__dict__ÖеĶÔÏóÊÇ°éËæfµÄ´æÔÚ¶ø´æÔÚµÄ
ÁíÍâdir£¨£©ºÍlocals().keys()µÄ½á¹ûÄÚÈÝÒ»Ñù£¬µ«ÊÇÁ½Õß˳ÐòÊDz»Ò»ÑùµÄ
ºóÕßµÄ˳ÐòÕýÊÇÏú»ÙnamespaceʱºòµÄ˳Ðò


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

2006年11月10日 星期五 16:52

=?GB2312?B?u8aPqg==?= yellowfool在gmail.com
星期五 十一月 10 16:52:39 HKT 2006

locals()²»´í£¬ºÇ¡£
locals()·µ»ØµÄ¾ÍÊǵ±Ç°¶ÔÏóµÄ__dict__£¬¶ÔÏóµÄ__dict__ÊôÐÔ£¬×ÔÉíÎÞ·¨Ö±½ÓÒýÓÃ
ллamingsc£¬Õâ»Ø×ÜËãÊÇÇå³þ ÁË

ÔÚ06-11-10£¬amingsc <amingsc在gmail.com> дµÀ£º
>
>
>
> »Æª дµÀ:
> >
> > ÔÚ06-11-10£¬*amingsc* <amingsc在gmail.com amingsc在gmail.com>>
> > дµÀ£º
> >
> >     ÕâÀïµÄ˳Ðò²»ÊÇdirËùÏÔʾ³öÀ´µÄ×Öĸ˳Ðò£¬¶øÊÇdictÄÚ²¿µÄhashË÷ÒýµÄ˳
> >     Ðò£¬Òò
> >     ΪnamespaceÖеÄËùÓжÔÏó¶¼ÊÇÒÔdictµÄ·½Ê½±£´æµÄ£¬ÎÒ²ÂÏëÓ¦¸ÃÊÇÕâÑùʵ
> >     Ïֵģ¬
> >     Äã¿ÉÒÔÈ¥Éè¼Æ¸öʵÑéÊÔÊÔ
> >
> > лл*amingsc*£¬Ô­À´ÊÇÕâÑù£¬¿ÉÊDz»ÖªµÀÔõô²ÅÄÜ¿´µÃµ½Êµ¼ÊµÄ˳Ðò£¬²»¹ýÕâ
> > ÑùÇî×·²»ÉáËƺõҲûʲô±ØÒª¡£Ä£¿éÖеÄ__dict__Ó¦¸Ã´æ·ÅÄ£¿éÃüÃû¿Õ¼ä°É£¬È´
> > ÊÇÔõôÄÜ¿´µ½ÄØ£¿
> >
> ²»ÖªµÀ__dict__ÊǸÉÂïµÄ£¬²»¹ýºÃÏñ__dict__ÀïÃæ±£´æµÄ¶ÔÏó¶¼ÊÇ¿ÉÒÔÔÚÍâÃæ·ÃÎʵÄ
> ÔËÐÐÒ»ÏÂÏÂÃæµÄÀý×Ó¿ÉÒÔ¿´³öÆ京Ò壺
> def f(a):
> *****f.b = a
> *****c = a+1
> *****print locals()
>
> f(2)
> f.__dict__
> f.d=3
> f.__dict__
> ÉÏÃælocals£¨£©ÔòÏÔʾÁËnamespace£¬ÄÇÊǼ´Ê±µÄ
> ¶ø__dict__ÖеĶÔÏóÊÇ°éËæfµÄ´æÔÚ¶ø´æÔÚµÄ
> ÁíÍâdir£¨£©ºÍlocals().keys()µÄ½á¹ûÄÚÈÝÒ»Ñù£¬µ«ÊÇÁ½Õß˳ÐòÊDz»Ò»ÑùµÄ
> ºóÕßµÄ˳ÐòÕýÊÇÏú»ÙnamespaceʱºòµÄ˳Ðò
>
>
>
> _______________________________________________
> 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/20061110/004c6fe8/attachment.htm 

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

2006年11月10日 星期五 17:24

amingsc amingsc在gmail.com
星期五 十一月 10 17:24:15 HKT 2006

¹þ¹þ£¬²»ÊÇÄÇô»ØÊÂ
locals£¨£©¸ú__dict__¸ù±¾¾ÍÊÇÁ½»ØÊ£¬ËäÈ»ÓÐʱÁ½ÕßÊÇÏàËƵÄ
ÕâÊDz»Í¬µÄ¸ÅÄî
localsÊDZ¾µØÃû×ֿռ䣬ÊÇij±äÁ¿ËùÔÚ×÷ÓÃÓòÄÚµÄËùÓпɼû¶ÔÏóµÄ¼¯ºÏ
__dict__ÊÇij¶ÔÏóËùÓµÓеÄÊôÐÔ»ò·½·¨µÄ¼¯ºÏ
±ÈÈç
class A:
****def fun(self,x):pass
a=A£¨£©
a.fun£¨x=1£©
ÕâʱʵÖÊÉϵÄÖ´Ðйý³ÌÊÇa.__dict__['fun'](x=1)

ºÃºÃÌå»áһϰɣ¬È·ÊµÊDz»Ò»ÑùµÄ
»Æª дµÀ:
> locals()²»´í£¬ºÇ¡£
> locals()·µ»ØµÄ¾ÍÊǵ±Ç°¶ÔÏóµÄ__dict__£¬¶ÔÏóµÄ__dict__ÊôÐÔ£¬×ÔÉíÎÞ·¨Ö±½ÓÒýÓÃ
> ллamingsc£¬Õâ»Ø×ÜËãÊÇÇå³þ ÁË
> ÔÚ06-11-10£¬*amingsc* <amingsc at gmail.com amingsc at gmail.com>>
> дµÀ£º
>
>
>
>     »Æª дµÀ:
>     >
>     > ÔÚ06-11-10£¬*amingsc* <amingsc at gmail.com
>     amingsc at gmail.com> amingsc at gmail.com
>     amingsc at gmail.com>>>
>     > дµÀ£º
>     >
>     > ÕâÀïµÄ˳Ðò²»ÊÇdirËùÏÔʾ³öÀ´µÄ×Öĸ˳Ðò£¬¶øÊÇdictÄÚ²¿µÄhashË÷ÒýµÄ˳
>     > Ðò£¬Òò
>     > ΪnamespaceÖеÄËùÓжÔÏó¶¼ÊÇÒÔdictµÄ·½Ê½±£´æµÄ£¬ÎÒ²ÂÏëÓ¦¸ÃÊÇÕâÑùʵ
>     > Ïֵģ¬
>     > Äã¿ÉÒÔÈ¥Éè¼Æ¸öʵÑéÊÔÊÔ
>     >
>     > лл*amingsc*£¬Ô­À´ÊÇÕâÑù£¬¿ÉÊDz»ÖªµÀÔõô²ÅÄÜ¿´µÃµ½Êµ¼ÊµÄ˳Ðò£¬
>     ²»¹ýÕâ
>     > ÑùÇî×·²»ÉáËƺõҲûʲô±ØÒª¡£Ä£¿éÖеÄ__dict__Ó¦¸Ã´æ·ÅÄ£¿éÃüÃû¿Õ¼ä
>     °É£¬È´
>     > ÊÇÔõôÄÜ¿´µ½ÄØ£¿
>     >
>     ²»ÖªµÀ__dict__ÊǸÉÂïµÄ£¬²»¹ýºÃÏñ__dict__ÀïÃæ±£´æµÄ¶ÔÏó¶¼ÊÇ¿ÉÒÔÔÚÍâ
>     Ãæ·ÃÎʵÄ
>     ÔËÐÐÒ»ÏÂÏÂÃæµÄÀý×Ó¿ÉÒÔ¿´³öÆ京Ò壺
>     def f(a):
>     *****f.b = a
>     *****c = a+1
>     *****print locals()
>
>     f(2)
>     f.__dict__
>     f.d=3
>     f.__dict__
>     ÉÏÃælocals£¨£©ÔòÏÔʾÁËnamespace£¬ÄÇÊǼ´Ê±µÄ
>     ¶ø__dict__ÖеĶÔÏóÊÇ°éËæfµÄ´æÔÚ¶ø´æÔÚµÄ
>     ÁíÍâdir£¨£©ºÍlocals().keys()µÄ½á¹ûÄÚÈÝÒ»Ñù£¬µ«ÊÇÁ½Õß˳ÐòÊDz»Ò»ÑùµÄ
>     ºóÕßµÄ˳ÐòÕýÊÇÏú»ÙnamespaceʱºòµÄ˳Ðò
>
>
>
>     _______________________________________________
>     python-chinese
>     Post: send python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>
>     Subscribe: send subscribe to
>     python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     Unsubscribe: send unsubscribe to
>     python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号