best way to get data into a new instance?

Bruno Desthuilliers onurb at xiludom.gro
Thu Sep 28 11:33:59 EDT 2006


John Salerno wrote:
> Let's pretend I'm creating an Employee class, which I will later
> subclass for more specific jobs.

Let's pretend it might be a good design... <g>

> Each instance will have stuff like a
> name, title, degrees held, etc. etc.
> 
> So I'm wondering, is the best way to get all this information into the
> object to just have a really long __init__ method that takes each argument?

what about optional arguments ?

class Employee(object):
  def __init__(self, id, name, **kw):
    self.id = id
    self.name = name
    self.titles = kw.get('titles', [])
    self.birthdate = kw.get(birthdate, None)
    # etc

> Does a question like this depend on how the class will be used? 

I don't think it would make sens to design anything without any hint
about how it's supposed to be used.

My 2 cents
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list