How to write a constructor accepting initialization and file persistence?

Grzegorz Adam Hankiewicz gradha at titanium.sabren.com
Wed Jun 4 07:02:39 EDT 2003


Since Python doesn't have function overloading, I don't know very
well what's the best way to write the constructor of an object which
should accept initialization parameters or an xml.dom.minidom node
storing it's data. My aproximation:

class something(parent):

   def __init__(self, one, two, three, file_data = None)
      super(something, self).__init__(one, three, file_data)
      if file_data:
         init_extra_attributes_from_file_data()
      else:
         init_extra_attributes_from_parameters(one, two, thre)

Maybe I could use **keywords, but this forces the caller to always
name the parameters. Is there any other way?

-- 
 Please don't send me private copies of your public answers. Thanks.





More information about the Python-list mailing list