Hi Mr. Terra,

Thanks so much for these links and your help.  Definitely appreciated.  I 
know I'll just end up using the ModelSerializer class but I like to 
understand what is going on underneath to a reasonable level and it bugs me 
when I can't figure something that I know is basic out.



On Thursday, March 14, 2013 5:23:53 PM UTC-4, Andre Terra (airstrike) wrote:
>
> This is a much better explanation on the use of *args and **keywordargs 
> (**kwargs)
>
>
> http://www.saltycrane.com/blog/2008/01/how-to-use-args-and-kwargs-in-python/
>
> On Thu, Mar 14, 2013 at 6:22 PM, Andre Terra <[email protected]<javascript:>
> > wrote:
>
>> About the asterisks, please checkout this link:
>>
>> http://stackoverflow.com/questions/4306574/python-method-function-arguments-starting-with-asterisk-and-dual-asterisk
>>
>> the difference between dict['key'] and dict.get('key', 'something') is 
>> that the second doesn't raise a KeyError exception when 'key' isn't in the 
>> dict; instead, it returns 'something'. this allows for shorter code. please 
>> compare:
>>
>> try:
>>     max_retries = config['max_retries']
>> except KeyError:
>>     max_retries = 10
>>
>> versus
>>
>> max_retries = config.get('max_retries', 10)
>>
>>
>>
>> Cheers,
>> AT
>>
>>
>> On Thu, Mar 14, 2013 at 6:17 PM, lamen <[email protected] 
>> <javascript:>>wrote:
>>
>>> Hello,
>>>
>>> Not sure what the difference is in the usage of attrs 
>>> I could not find the documentation for this although I'm sure it's going 
>>> to be obvious after the fact.
>>>
>>> Also, could someone tell me what the double asterisks mean in the line
>>> return Comment(**attrs)
>>> ?
>>>
>>> Is this some type of variable length parameter list?  How would 
>>>
>>> return Comment(*attrs) 
>>>
>>> and
>>>
>>>  return Comment(attrs) 
>>>  vs
>>>
>>> be different?
>>>
>>> Thank you!
>>>
>>> class CommentSerializer(serializers.Serializer):
>>>     email = serializers.EmailField()
>>>     content = serializers.CharField(max_length=200)
>>>     created = serializers.DateTimeField()
>>>
>>>     def restore_object(self, attrs, instance=None):
>>>         if instance is not None:
>>>             instance.title = attrs['title']
>>>             instance.content = attrs['content']
>>>             instance.created = attrs['created']
>>>             return instance
>>>         return Comment(**attrs)
>>>
>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected] <javascript:>.
>>> To post to this group, send email to [email protected]<javascript:>
>>> .
>>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>  
>>>  
>>>
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to