Re: best way to get data into a new instance?
- From: Bruno Desthuilliers <onurb@xxxxxxxxxxx>
- Date: Thu, 28 Sep 2006 17:33:59 +0200
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@xxxxxxxxxxx'.split('@')])"
.
- References:
- best way to get data into a new instance?
- From: John Salerno
- best way to get data into a new instance?
- Prev by Date: Re: XML parser that sorts elements?
- Next by Date: Re: License / Registration key enabled software
- Previous by thread: Re: best way to get data into a new instance?
- Next by thread: Re: best way to get data into a new instance?
- Index(es):
Relevant Pages
|