Re: Possible Basic kwargs question.

2013-04-17 Thread Rainy
When the definition is method(self, **kwargs), you ARE asking
variable named kwargs. If you want to accept one dict object,
it should be: method(self, mydict). If you want to accept variable
list of args, it should be method(self, *mylist)

-ak


On Wednesday, April 17, 2013 12:59:21 AM UTC-4, jayhalleaux wrote:
>
> but if I did that then i would have a variable named kwargs.
>
> and it would be print kwargs['param1'], etc
>
> Why even unpack the dictionary?  I could just pass the dictionary instead.
>
>
> On Tuesday, April 16, 2013 11:08:42 PM UTC-4, Brad Pitcher wrote:
>>
>> It should be:
>> model.method1(**params)
>> On Apr 16, 2013 7:49 PM, "jayhalleaux"  wrote:
>>
>>> Not really a Django question but I'm trying to create a model method 
>>> that does not have a fixed set of parameters.
>>>
>>> models.py
>>> Class Model_A(model.Model):
>>> ...
>>>
>>> def method1(self, **kwargs):
>>>
>>> print param1, param2, param3
>>>
>>>
>>>
>>> views.py
>>> params = dict(
>>>
>>> param1=something1,
>>> param2=something2,
>>> param3=something3,
>>> ...
>>>
>>> )
>>>
>>> model.method1(params)
>>>
>>> In this example when I try to do something like this it states that I 
>>> should have passed only 1 parameter instead of 2.
>>>
>>> I thought the whole point of using '**' to unpack dictionaries is so you 
>>> don't have to have a fixed number of parameters.
>>>
>>> Is there something I am missing or am I doing this incorrect? First time 
>>> I'm trying to create a method like this.  Normally I explicitly state all 
>>> parameters.
>>>
>>> Any help is appreciated.
>>>
>>> -- 
>>> 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 django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> 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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Possible Basic kwargs question.

2013-04-16 Thread Mario Gudelj
I think this might be a useful article for you
http://agiliq.com/blog/2012/06/understanding-args-and-kwargs/


On 17 April 2013 15:45, Brad Pitcher  wrote:

> I see what you're saying. Maybe you're looking for something more like
> this?
>
> def method1(self, param1=sensible_default, param2=sensible_default,
> param3=sensible_default):
> print param1, param2, param3
>
> The variable names must be specified in the method arguments like above if
> you wish to reference them by name inside the method itself. With this
> method, you will also need to call it with: model.method1(**params)
>
>
> On Tue, Apr 16, 2013 at 9:59 PM, jayhalleaux wrote:
>
>> but if I did that then i would have a variable named kwargs.
>>
>> and it would be print kwargs['param1'], etc
>>
>> Why even unpack the dictionary?  I could just pass the dictionary instead.
>>
>>
>> On Tuesday, April 16, 2013 11:08:42 PM UTC-4, Brad Pitcher wrote:
>>
>>> It should be:
>>> model.method1(**params)
>>> On Apr 16, 2013 7:49 PM, "jayhalleaux"  wrote:
>>>
  Not really a Django question but I'm trying to create a model method
 that does not have a fixed set of parameters.

 models.py
 Class Model_A(model.Model):
 ...

 def method1(self, **kwargs):

 print param1, param2, param3



 views.py
 params = dict(

 param1=something1,
 param2=something2,
  param3=something3,
 ...

 )

 model.method1(params)

 In this example when I try to do something like this it states that I
 should have passed only 1 parameter instead of 2.

 I thought the whole point of using '**' to unpack dictionaries is so
 you don't have to have a fixed number of parameters.

 Is there something I am missing or am I doing this incorrect? First
 time I'm trying to create a method like this.  Normally I explicitly state
 all parameters.

 Any help is appreciated.

 --
 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 django-users...@**googlegroups.com.
 To post to this group, send email to django...@googlegroups.com.

 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 django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> 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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Possible Basic kwargs question.

2013-04-16 Thread Brad Pitcher
I see what you're saying. Maybe you're looking for something more like this?

def method1(self, param1=sensible_default, param2=sensible_default,
param3=sensible_default):
print param1, param2, param3

The variable names must be specified in the method arguments like above if
you wish to reference them by name inside the method itself. With this
method, you will also need to call it with: model.method1(**params)

On Tue, Apr 16, 2013 at 9:59 PM, jayhalleaux  wrote:

> but if I did that then i would have a variable named kwargs.
>
> and it would be print kwargs['param1'], etc
>
> Why even unpack the dictionary?  I could just pass the dictionary instead.
>
>
> On Tuesday, April 16, 2013 11:08:42 PM UTC-4, Brad Pitcher wrote:
>
>> It should be:
>> model.method1(**params)
>> On Apr 16, 2013 7:49 PM, "jayhalleaux"  wrote:
>>
>>>  Not really a Django question but I'm trying to create a model method
>>> that does not have a fixed set of parameters.
>>>
>>> models.py
>>> Class Model_A(model.Model):
>>> ...
>>>
>>> def method1(self, **kwargs):
>>>
>>> print param1, param2, param3
>>>
>>>
>>>
>>> views.py
>>> params = dict(
>>>
>>> param1=something1,
>>> param2=something2,
>>>  param3=something3,
>>> ...
>>>
>>> )
>>>
>>> model.method1(params)
>>>
>>> In this example when I try to do something like this it states that I
>>> should have passed only 1 parameter instead of 2.
>>>
>>> I thought the whole point of using '**' to unpack dictionaries is so you
>>> don't have to have a fixed number of parameters.
>>>
>>> Is there something I am missing or am I doing this incorrect? First time
>>> I'm trying to create a method like this.  Normally I explicitly state all
>>> parameters.
>>>
>>> Any help is appreciated.
>>>
>>> --
>>> 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 django-users...@**googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>>
>>> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> 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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Possible Basic kwargs question.

2013-04-16 Thread jayhalleaux
but if I did that then i would have a variable named kwargs.

and it would be print kwargs['param1'], etc

Why even unpack the dictionary?  I could just pass the dictionary instead.


On Tuesday, April 16, 2013 11:08:42 PM UTC-4, Brad Pitcher wrote:
>
> It should be:
> model.method1(**params)
> On Apr 16, 2013 7:49 PM, "jayhalleaux" > 
> wrote:
>
>> Not really a Django question but I'm trying to create a model method that 
>> does not have a fixed set of parameters.
>>
>> models.py
>> Class Model_A(model.Model):
>> ...
>>
>> def method1(self, **kwargs):
>>
>> print param1, param2, param3
>>
>>
>>
>> views.py
>> params = dict(
>>
>> param1=something1,
>> param2=something2,
>> param3=something3,
>> ...
>>
>> )
>>
>> model.method1(params)
>>
>> In this example when I try to do something like this it states that I 
>> should have passed only 1 parameter instead of 2.
>>
>> I thought the whole point of using '**' to unpack dictionaries is so you 
>> don't have to have a fixed number of parameters.
>>
>> Is there something I am missing or am I doing this incorrect? First time 
>> I'm trying to create a method like this.  Normally I explicitly state all 
>> parameters.
>>
>> Any help is appreciated.
>>
>> -- 
>> 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 django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> 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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Possible Basic kwargs question.

2013-04-16 Thread Brad Pitcher
It should be:
model.method1(**params)
On Apr 16, 2013 7:49 PM, "jayhalleaux"  wrote:

> Not really a Django question but I'm trying to create a model method that
> does not have a fixed set of parameters.
>
> models.py
> Class Model_A(model.Model):
> ...
>
> def method1(self, **kwargs):
>
> print param1, param2, param3
>
>
>
> views.py
> params = dict(
>
> param1=something1,
> param2=something2,
> param3=something3,
> ...
>
> )
>
> model.method1(params)
>
> In this example when I try to do something like this it states that I
> should have passed only 1 parameter instead of 2.
>
> I thought the whole point of using '**' to unpack dictionaries is so you
> don't have to have a fixed number of parameters.
>
> Is there something I am missing or am I doing this incorrect? First time
> I'm trying to create a method like this.  Normally I explicitly state all
> parameters.
>
> Any help is appreciated.
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> 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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Possible Basic kwargs question.

2013-04-16 Thread jayhalleaux
Not really a Django question but I'm trying to create a model method that 
does not have a fixed set of parameters.

models.py
Class Model_A(model.Model):
...

def method1(self, **kwargs):

print param1, param2, param3



views.py
params = dict(

param1=something1,
param2=something2,
param3=something3,
...

)

model.method1(params)

In this example when I try to do something like this it states that I 
should have passed only 1 parameter instead of 2.

I thought the whole point of using '**' to unpack dictionaries is so you 
don't have to have a fixed number of parameters.

Is there something I am missing or am I doing this incorrect? First time 
I'm trying to create a method like this.  Normally I explicitly state all 
parameters.

Any help is appreciated.

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.