Thanks for all the explanations, everyone. This does make sense, and I
am now using the
if(arg==None): arg=self.arg
idea. It only adds a couple lines, and is, if anything, more explicit
than what I was doing before.

On 5/27/10, Mark Lawrence <breamore...@yahoo.co.uk> wrote:
> On 23/05/2010 20:40, Alex Hall wrote:
>> Hello all,
>> I know Python reasonably well, but I still run into basic questions
>> which those over on the other python list request I post here instead.
>> I figure this would be one of them:
>> Why would this not work:
>>
>> class c(object):
>>   def __init__(self, arg1, arg2):
>>    self.arg1=arg1
>>    self.arg2=arg2
>>
>>   def doSomething(self, arg3=self.arg1):
>>    ...
>>
>> The above results in an error that "name 'self' is not defined". Why
>> can I not set the default values of a method's arguments to class vars
>> like that? Thanks!
>>
>>
> You've already had some explanations as to what happens, but what are
> you trying to achieve?  Why don't you forget about arg3 because it is
> arg1, which must exist by creating an instance of class c, or you
> wouldn't be able to call doSomething in the first place?
>
> HTH.
>
> Mark Lawrence
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to