Leandro Lameiro wrote:
> If I understand your problem correctly, you can use Python double-
star
> syntax.
>
> people = [ { 'title':'Mr','name':'Darth','lastname':'Vader' },
> {'name':'Luke','lastname':'Skywalker'} ]
>
> for person in people:
> Person(**person))
>
> It will "open" the dict into keyword arguments, if the argument is
not
> there (like in your second item in the list, that is missing title),
> it will simply not pass it, making Elixir create it as None (if the
> field is not required).
This is true, and you can write your own constructor if you want to
override the behavior of the default constructor:
class Person(Entity):
has_field('name', Unicode, required=True)
has_field('lastname', Unicode, required=True)
has_field('title', Unicode)
def __init__(self, name='', lastname='', title='No Title'):
self.name = name
self.lastname = lastname
self.title = title
people = [
{ 'title':'Mr','name':'Darth','lastname':'Vader' },
{'name':'Luke', 'lastname':'Skywalker'}
]
for person in people:
Person(**person)
No need for changes in Elixir, you just need to take better advantage of
what Python has to offer :)
--
Jonathan LaCour
http://cleverdevil.org
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---