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]> 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].
> 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.
>
>
>

-- 
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