What's wrong with it?

lee lion dance_code at hotmail.com
Mon Sep 30 11:12:38 EDT 2002

Hi, What's wrong with it?
class Borg(object):
  _shared_state = {}
  def __new__(cls):
    return cls._shared_state

class Singleton(Borg):
  def __new__(cls, arg):
    self = Borg.__new__(cls)
    self['val'] = arg
    return self
def main():
  x = Singleton('sausage')

When running:
Traceback (most recent call last):
  File "D:\Programming\Python22\my_Python_programs\MyBorgSingleton.py", 
line 27, in ?
  File "D:\Programming\Python22\my_Python_programs\MyBorgSingleton.py", 
line 16, in main
    x = Singleton('sausage')
ValueError: dictionary update sequence element #0 has length 1; 2 is 

Could anyone tell me why it broke with that strange runtime error?

Thank in advance,

"The best way of living is to earn a little more than you cost and to cost 
just as you need to."
                                      Li Hang

与联机的朋友进行交流,请使用 MSN Messenger: 

More information about the Python-list mailing list