Python堆bug?

时间:2014-10-30 09:29:06

标签: python dictionary

#!/usr/bin/python

class s:
        def __init__( self ):
                print 'init'

        def f( self, method, req = {} ):
                print 'req income: ', req
                req['method'] = method
                if method == 'first':
                        req['first'] = 'here'
                elif method == 'second':
                        req['second'] = 'here'
                elif method == 'third':
                        req['third'] = 'here'
                print 'req after: ', req
                print ''

        def a( self ):
                self.f( 'first' )

        def b( self ):
                self.f( 'second', { 'val': 2 } )

        def c( self ):
                self.f( 'third' )


d = s()
d.a()
d.b()
d.c()

当我发布时:

$ python heap_bug.py 
req income:  {}
req after:  {'method': 'first', 'first': 'here'}

req income:  {'val': 2}
req after:  {'second': 'here', 'method': 'second', 'val': 2}

req income:  {'method': 'first', 'first': 'here'}
req after:  {'method': 'third', 'third': 'here', 'first': 'here'}

如何处理?我是否必须指定所有参数每次以各种方式

我正在谈论这个错误:

req after:  {'method': 'third', 'third': 'here', 'first': 'here'} 
你可以带我一起走路吗?

0 个答案:

没有答案