On Jul 19, 3:38 am, "Gaetan de Menten" <[EMAIL PROTECTED]> wrote:
> > My question is how could I make the Class intelligently figure out
> > what data I am passing and what not during instantiation, so I don't
> > have to explicitly write code for missing or not missing data. Ideally
> > what I would like to do, is pass just a dictionary that is of the form
> > { 'field_name':field_data }, and let the class figure what goes where
> > and what is missing.
>
> Sorry, I don't understand what you want here. Could you provide a more
> complete example?
Here goes an example
class Person(Entity):
has_field('name',Unicode,required=True)
has_field('lastname',Unicode,required=True)
has_field('title',Unicode)
Assuming I have a list of like this dictionaries: people =
[ { 'title':'Mr','name':'Darth','lastname':'Vader' },
{'name':'Luke','lastname':'Skywalker'} ]
for person in people:
Person(person)
If title is missing from the dictionary then it is assumed to be None.
This example is very simple but I have a few tables where a lot of
missing fields can happen. I like this more than:
if not people.has_key(title):
title = None
else:
title = people['title']
Person(name=name,lastname=lastname,title=title)
Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---