0

After a good bit of searching i couldn’t find any examples covering this. But i might not be using the correct terminology, since im confused about the situation, and what to even ask if that makes sense? So i feel like this is a duplicate probably.

But if you have a Python class, with two methods that have a parameter that has the same name, whats the behaviour of this?

class Foo():

    def __init__(self, arg1=1, arg2=2):

    def methodOne(self, amount, setting=None, extra=0):         

    def methodTwo(self, amount, setting=None):
        ...
        #What is going on with setting here? What is setting referring to?
        self.methodOne(amount, setting=setting) 
1
  • @John1024 self is defined in the code im looking at, forgot to put that, ive updated question. Commented Aug 11, 2014 at 2:49

1 Answer 1

1

The setting on the left can only be referring to a keyword argument, and the setting on the right can only be referring to a name. That's how Python's parser works.

Sign up to request clarification or add additional context in comments.

6 Comments

I forgot to add self in my question, as the code im looking at has self defined, now it matches up, so maybe that changes your answer?
No. The Python parser does not change.
Ahh okay, well in that case, im still not understanding lol. What do you mean by "keyword argument" and "name"?
Okay so in self.methodOne(amount, setting=setting) , the second argument is a keyword argument? And you just happen to be passing the value setting? Just as well it could be something like self.methodOne(amount, setting='no')? I think i understand now.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.