Passing argument from method using superWhat's the difference between a method and a function?What is the difference between Python's list methods append and extend?Understanding Python super() with __init__() methodsStatic methods in Python?How do I pass a variable by reference?“Least Astonishment” and the Mutable Default Argument'Must Override a Superclass Method' Errors after importing a project into EclipseDoes Python have a string 'contains' substring method?Passing Data between View Controllersusing subclass attribute in the main class in python
Movie with Zoltar in a trailer park named Paradise and a boy playing a video game then being recruited by aliens to fight in space
Could this problem be tackled using Mathematica?
Why were the first airplanes "backwards"?
Discworld quote about an "old couple" who having said everything to each other, can finally go about living their lives
Should 私の be omitted?
Reusable spacecraft: why still have fairings detach, instead of open/close?
What is quadratization?
pgfmath does not work
Can dual citizens open crypto exchange accounts where U.S. citizens are prohibited?
Different budgets within roommate group
Why wasn't EBCDIC designed with contiguous alphanumeric characters?
Fully submerged water bath for stove top baking?
Does the CPT theorem hold for all spacetime dimensions?
How did Lefschetz do mathematics without hands?
Is there a way to convert blue ice back into packed ice?
Does a return economy-class seat between London and San Francisco release 5.28 tonnes of CO2 equivalents?
Preferred word for "preferred", "target", "chosen" in end user support documentation
I just started should I accept a farewell lunch for a coworker I don't know?
If two black hole event horizons overlap (touch) can they ever separate again?
What European countries have secret voting within the Legislature?
Could human civilization live 150 years in a nuclear-powered aircraft carrier colony without resorting to mass killing/ cannibalism?
Having to constantly redo everything because I don't know how to do it?
How can I deal with extreme temperatures in a hotel room?
Word ending in "-ine" for rat-like
Passing argument from method using super
What's the difference between a method and a function?What is the difference between Python's list methods append and extend?Understanding Python super() with __init__() methodsStatic methods in Python?How do I pass a variable by reference?“Least Astonishment” and the Mutable Default Argument'Must Override a Superclass Method' Errors after importing a project into EclipseDoes Python have a string 'contains' substring method?Passing Data between View Controllersusing subclass attribute in the main class in python
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to set an argument role='r' under a method called getphone. It's working ok under init using super but I can't figure out how to do it under another method
The role is to set the permission level for the api that is running
this code is working
PATH = 'home_drive_'
PLATFORM = 'Linux_'
ITEM = '_PC'
class Credential:
def __init__(self, *, path, platform, role='', **kwargs):
super().__init__(**kwargs)
self.role = role
self.username_file = path + platform + role
class AXL(Credential):
def __init__(self, *, item, **kwargs):
super().__init__(role='rw', **kwargs)
self.item = item
def getphone(self):
self.role = 'r'
return self.username_file + self.item
def writephone(self):
self.role = 'rw'
return self.username_file + self.item
def statusphone(self):
self.role = 'rwx'
return self.username_file + self.item
reg1 = AXL(path=PATH, platform=PLATFORM, item=ITEM)
print(reg1.getphone())
print(reg1.writephone())
print(reg1.statusphone())
under the class AXL, I want to move the role='r' under the method getphone
I've tried this and it's working but i don't understand why i need to put the path and platform.
PATH = 'home_drive_'
PLATFORM = 'Linux_'
ITEM = '_PC'
class Credential:
def __init__(self, *, path, platform, role='', **kwargs):
super().__init__(**kwargs)
self.role = role
self.username_file = path + platform + role
class AXL(Credential):
def __init__(self, *, item, **kwargs):
super().__init__(**kwargs)
self.item = item
def getphone(self):
super().__init__(path=PATH, platform=PLATFORM, role='r')
return self.username_file + self.item
def writephone(self):
super().__init__(path=PATH, platform=PLATFORM, role='rw')
return self.username_file + self.item
def statusphone(self):
super().__init__(path=PATH, platform=PLATFORM, role='rwx')
return self.username_file + self.item
reg1 = AXL(path=PATH, platform=PLATFORM, item=ITEM)
print(reg1.getphone())
print(reg1.writephone())
print(reg1.statusphone())
a sandbox can be found here
python oop superclass
|
show 1 more comment
I'm trying to set an argument role='r' under a method called getphone. It's working ok under init using super but I can't figure out how to do it under another method
The role is to set the permission level for the api that is running
this code is working
PATH = 'home_drive_'
PLATFORM = 'Linux_'
ITEM = '_PC'
class Credential:
def __init__(self, *, path, platform, role='', **kwargs):
super().__init__(**kwargs)
self.role = role
self.username_file = path + platform + role
class AXL(Credential):
def __init__(self, *, item, **kwargs):
super().__init__(role='rw', **kwargs)
self.item = item
def getphone(self):
self.role = 'r'
return self.username_file + self.item
def writephone(self):
self.role = 'rw'
return self.username_file + self.item
def statusphone(self):
self.role = 'rwx'
return self.username_file + self.item
reg1 = AXL(path=PATH, platform=PLATFORM, item=ITEM)
print(reg1.getphone())
print(reg1.writephone())
print(reg1.statusphone())
under the class AXL, I want to move the role='r' under the method getphone
I've tried this and it's working but i don't understand why i need to put the path and platform.
PATH = 'home_drive_'
PLATFORM = 'Linux_'
ITEM = '_PC'
class Credential:
def __init__(self, *, path, platform, role='', **kwargs):
super().__init__(**kwargs)
self.role = role
self.username_file = path + platform + role
class AXL(Credential):
def __init__(self, *, item, **kwargs):
super().__init__(**kwargs)
self.item = item
def getphone(self):
super().__init__(path=PATH, platform=PLATFORM, role='r')
return self.username_file + self.item
def writephone(self):
super().__init__(path=PATH, platform=PLATFORM, role='rw')
return self.username_file + self.item
def statusphone(self):
super().__init__(path=PATH, platform=PLATFORM, role='rwx')
return self.username_file + self.item
reg1 = AXL(path=PATH, platform=PLATFORM, item=ITEM)
print(reg1.getphone())
print(reg1.writephone())
print(reg1.statusphone())
a sandbox can be found here
python oop superclass
If i understand correctly, you can setself.role = 'r'insideAXL.final.
– heemayl
Mar 25 at 14:43
If I understand you correctly, you can't (at least not in any way that conforms to conventions and that will be easy to debug).roleis required to initialize aCredentialinstance so it must be provided when initializing anAXLinstance.
– DeepSpace
Mar 25 at 14:44
It's not clear what your ultimate goal is. Do you want to replace the attributeusername_file(currently initialized in__init__) with a method that computes a value using a given role when called? (Which would convertrolefrom an attribute of an instance to simply an argument tofinal.)
– chepner
Mar 25 at 15:02
for example, i would have AXL.getphone, AXL.writephone and AXL.statusphone. getphone's role is read-only (r) writephone's role is read/write (rw) statusphone's role is read/write/execute (rwx) Depending of the role, the credential would return the username/pwd to use thank you
– Louis-Philippe Descamps
Mar 25 at 15:22
@chepner, this is what I'm trying to do repl.it/@louis_philippedescamps/…
– Louis-Philippe Descamps
Mar 26 at 9:17
|
show 1 more comment
I'm trying to set an argument role='r' under a method called getphone. It's working ok under init using super but I can't figure out how to do it under another method
The role is to set the permission level for the api that is running
this code is working
PATH = 'home_drive_'
PLATFORM = 'Linux_'
ITEM = '_PC'
class Credential:
def __init__(self, *, path, platform, role='', **kwargs):
super().__init__(**kwargs)
self.role = role
self.username_file = path + platform + role
class AXL(Credential):
def __init__(self, *, item, **kwargs):
super().__init__(role='rw', **kwargs)
self.item = item
def getphone(self):
self.role = 'r'
return self.username_file + self.item
def writephone(self):
self.role = 'rw'
return self.username_file + self.item
def statusphone(self):
self.role = 'rwx'
return self.username_file + self.item
reg1 = AXL(path=PATH, platform=PLATFORM, item=ITEM)
print(reg1.getphone())
print(reg1.writephone())
print(reg1.statusphone())
under the class AXL, I want to move the role='r' under the method getphone
I've tried this and it's working but i don't understand why i need to put the path and platform.
PATH = 'home_drive_'
PLATFORM = 'Linux_'
ITEM = '_PC'
class Credential:
def __init__(self, *, path, platform, role='', **kwargs):
super().__init__(**kwargs)
self.role = role
self.username_file = path + platform + role
class AXL(Credential):
def __init__(self, *, item, **kwargs):
super().__init__(**kwargs)
self.item = item
def getphone(self):
super().__init__(path=PATH, platform=PLATFORM, role='r')
return self.username_file + self.item
def writephone(self):
super().__init__(path=PATH, platform=PLATFORM, role='rw')
return self.username_file + self.item
def statusphone(self):
super().__init__(path=PATH, platform=PLATFORM, role='rwx')
return self.username_file + self.item
reg1 = AXL(path=PATH, platform=PLATFORM, item=ITEM)
print(reg1.getphone())
print(reg1.writephone())
print(reg1.statusphone())
a sandbox can be found here
python oop superclass
I'm trying to set an argument role='r' under a method called getphone. It's working ok under init using super but I can't figure out how to do it under another method
The role is to set the permission level for the api that is running
this code is working
PATH = 'home_drive_'
PLATFORM = 'Linux_'
ITEM = '_PC'
class Credential:
def __init__(self, *, path, platform, role='', **kwargs):
super().__init__(**kwargs)
self.role = role
self.username_file = path + platform + role
class AXL(Credential):
def __init__(self, *, item, **kwargs):
super().__init__(role='rw', **kwargs)
self.item = item
def getphone(self):
self.role = 'r'
return self.username_file + self.item
def writephone(self):
self.role = 'rw'
return self.username_file + self.item
def statusphone(self):
self.role = 'rwx'
return self.username_file + self.item
reg1 = AXL(path=PATH, platform=PLATFORM, item=ITEM)
print(reg1.getphone())
print(reg1.writephone())
print(reg1.statusphone())
under the class AXL, I want to move the role='r' under the method getphone
I've tried this and it's working but i don't understand why i need to put the path and platform.
PATH = 'home_drive_'
PLATFORM = 'Linux_'
ITEM = '_PC'
class Credential:
def __init__(self, *, path, platform, role='', **kwargs):
super().__init__(**kwargs)
self.role = role
self.username_file = path + platform + role
class AXL(Credential):
def __init__(self, *, item, **kwargs):
super().__init__(**kwargs)
self.item = item
def getphone(self):
super().__init__(path=PATH, platform=PLATFORM, role='r')
return self.username_file + self.item
def writephone(self):
super().__init__(path=PATH, platform=PLATFORM, role='rw')
return self.username_file + self.item
def statusphone(self):
super().__init__(path=PATH, platform=PLATFORM, role='rwx')
return self.username_file + self.item
reg1 = AXL(path=PATH, platform=PLATFORM, item=ITEM)
print(reg1.getphone())
print(reg1.writephone())
print(reg1.statusphone())
a sandbox can be found here
python oop superclass
python oop superclass
edited Mar 26 at 12:43
Louis-Philippe Descamps
asked Mar 25 at 14:41
Louis-Philippe DescampsLouis-Philippe Descamps
357 bronze badges
357 bronze badges
If i understand correctly, you can setself.role = 'r'insideAXL.final.
– heemayl
Mar 25 at 14:43
If I understand you correctly, you can't (at least not in any way that conforms to conventions and that will be easy to debug).roleis required to initialize aCredentialinstance so it must be provided when initializing anAXLinstance.
– DeepSpace
Mar 25 at 14:44
It's not clear what your ultimate goal is. Do you want to replace the attributeusername_file(currently initialized in__init__) with a method that computes a value using a given role when called? (Which would convertrolefrom an attribute of an instance to simply an argument tofinal.)
– chepner
Mar 25 at 15:02
for example, i would have AXL.getphone, AXL.writephone and AXL.statusphone. getphone's role is read-only (r) writephone's role is read/write (rw) statusphone's role is read/write/execute (rwx) Depending of the role, the credential would return the username/pwd to use thank you
– Louis-Philippe Descamps
Mar 25 at 15:22
@chepner, this is what I'm trying to do repl.it/@louis_philippedescamps/…
– Louis-Philippe Descamps
Mar 26 at 9:17
|
show 1 more comment
If i understand correctly, you can setself.role = 'r'insideAXL.final.
– heemayl
Mar 25 at 14:43
If I understand you correctly, you can't (at least not in any way that conforms to conventions and that will be easy to debug).roleis required to initialize aCredentialinstance so it must be provided when initializing anAXLinstance.
– DeepSpace
Mar 25 at 14:44
It's not clear what your ultimate goal is. Do you want to replace the attributeusername_file(currently initialized in__init__) with a method that computes a value using a given role when called? (Which would convertrolefrom an attribute of an instance to simply an argument tofinal.)
– chepner
Mar 25 at 15:02
for example, i would have AXL.getphone, AXL.writephone and AXL.statusphone. getphone's role is read-only (r) writephone's role is read/write (rw) statusphone's role is read/write/execute (rwx) Depending of the role, the credential would return the username/pwd to use thank you
– Louis-Philippe Descamps
Mar 25 at 15:22
@chepner, this is what I'm trying to do repl.it/@louis_philippedescamps/…
– Louis-Philippe Descamps
Mar 26 at 9:17
If i understand correctly, you can set
self.role = 'r' inside AXL.final.– heemayl
Mar 25 at 14:43
If i understand correctly, you can set
self.role = 'r' inside AXL.final.– heemayl
Mar 25 at 14:43
If I understand you correctly, you can't (at least not in any way that conforms to conventions and that will be easy to debug).
role is required to initialize a Credential instance so it must be provided when initializing an AXL instance.– DeepSpace
Mar 25 at 14:44
If I understand you correctly, you can't (at least not in any way that conforms to conventions and that will be easy to debug).
role is required to initialize a Credential instance so it must be provided when initializing an AXL instance.– DeepSpace
Mar 25 at 14:44
It's not clear what your ultimate goal is. Do you want to replace the attribute
username_file (currently initialized in __init__) with a method that computes a value using a given role when called? (Which would convert role from an attribute of an instance to simply an argument to final.)– chepner
Mar 25 at 15:02
It's not clear what your ultimate goal is. Do you want to replace the attribute
username_file (currently initialized in __init__) with a method that computes a value using a given role when called? (Which would convert role from an attribute of an instance to simply an argument to final.)– chepner
Mar 25 at 15:02
for example, i would have AXL.getphone, AXL.writephone and AXL.statusphone. getphone's role is read-only (r) writephone's role is read/write (rw) statusphone's role is read/write/execute (rwx) Depending of the role, the credential would return the username/pwd to use thank you
– Louis-Philippe Descamps
Mar 25 at 15:22
for example, i would have AXL.getphone, AXL.writephone and AXL.statusphone. getphone's role is read-only (r) writephone's role is read/write (rw) statusphone's role is read/write/execute (rwx) Depending of the role, the credential would return the username/pwd to use thank you
– Louis-Philippe Descamps
Mar 25 at 15:22
@chepner, this is what I'm trying to do repl.it/@louis_philippedescamps/…
– Louis-Philippe Descamps
Mar 26 at 9:17
@chepner, this is what I'm trying to do repl.it/@louis_philippedescamps/…
– Louis-Philippe Descamps
Mar 26 at 9:17
|
show 1 more comment
2 Answers
2
active
oldest
votes
There's no one role associated with an instance; rather, the role is associated with a method called by the instance. Try this.
PATH = 'home_drive_'
PLATFORM = 'Linux_'
ITEM = '_PC'
class Credential:
def __init__(self, *, path, platform, **kwargs):
super().__init__(**kwargs)
self.username_file = path + platform
class AXL(Credential):
def __init__(self, *, item, **kwargs):
super().__init__(**kwargs)
self.item = item
# "Private" method used to implement the other phone methods
# You could inline this if you want.
def _phone(self, role):
return self.username_file + role + self.item
def getphone(self):
return self._phone('r')
def writephone(self):
return self._phone('rw')
def statusphone(self):
return self._phone('rwx')
reg1 = AXL(path=PATH, platform=PLATFORM, item=ITEM)
print(reg1.getphone())
print(reg1.writephone())
print(reg1.statusphone())
that's working but not sure how I can use it in my real script that I copied here
– Louis-Philippe Descamps
Mar 26 at 15:10
It looks like anything involvingroleshould be a method that builds the path on the fly using arolearugment, rather than being an attribute of an instance. Or, you should have a lot more subclasses, each of which does have a fixed role.
– chepner
Mar 26 at 15:15
Hi, what about doing it like this. thanks
– Louis-Philippe Descamps
Mar 27 at 14:00
add a comment |
super() will let you access the parent class scope. You can access any method from it in the form super().method(args) in python3, with python 2 the format is super(YourClass,self).method(args).
Calling __init__ on the parent for each method doesn't seems to be right from the OOP perspective. You are reinitializing the parent object during its life time. If you want to set role from the parent you can simply use self.role = .... Any method on parent accessing self.role will see the modification.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55340337%2fpassing-argument-from-method-using-super%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
There's no one role associated with an instance; rather, the role is associated with a method called by the instance. Try this.
PATH = 'home_drive_'
PLATFORM = 'Linux_'
ITEM = '_PC'
class Credential:
def __init__(self, *, path, platform, **kwargs):
super().__init__(**kwargs)
self.username_file = path + platform
class AXL(Credential):
def __init__(self, *, item, **kwargs):
super().__init__(**kwargs)
self.item = item
# "Private" method used to implement the other phone methods
# You could inline this if you want.
def _phone(self, role):
return self.username_file + role + self.item
def getphone(self):
return self._phone('r')
def writephone(self):
return self._phone('rw')
def statusphone(self):
return self._phone('rwx')
reg1 = AXL(path=PATH, platform=PLATFORM, item=ITEM)
print(reg1.getphone())
print(reg1.writephone())
print(reg1.statusphone())
that's working but not sure how I can use it in my real script that I copied here
– Louis-Philippe Descamps
Mar 26 at 15:10
It looks like anything involvingroleshould be a method that builds the path on the fly using arolearugment, rather than being an attribute of an instance. Or, you should have a lot more subclasses, each of which does have a fixed role.
– chepner
Mar 26 at 15:15
Hi, what about doing it like this. thanks
– Louis-Philippe Descamps
Mar 27 at 14:00
add a comment |
There's no one role associated with an instance; rather, the role is associated with a method called by the instance. Try this.
PATH = 'home_drive_'
PLATFORM = 'Linux_'
ITEM = '_PC'
class Credential:
def __init__(self, *, path, platform, **kwargs):
super().__init__(**kwargs)
self.username_file = path + platform
class AXL(Credential):
def __init__(self, *, item, **kwargs):
super().__init__(**kwargs)
self.item = item
# "Private" method used to implement the other phone methods
# You could inline this if you want.
def _phone(self, role):
return self.username_file + role + self.item
def getphone(self):
return self._phone('r')
def writephone(self):
return self._phone('rw')
def statusphone(self):
return self._phone('rwx')
reg1 = AXL(path=PATH, platform=PLATFORM, item=ITEM)
print(reg1.getphone())
print(reg1.writephone())
print(reg1.statusphone())
that's working but not sure how I can use it in my real script that I copied here
– Louis-Philippe Descamps
Mar 26 at 15:10
It looks like anything involvingroleshould be a method that builds the path on the fly using arolearugment, rather than being an attribute of an instance. Or, you should have a lot more subclasses, each of which does have a fixed role.
– chepner
Mar 26 at 15:15
Hi, what about doing it like this. thanks
– Louis-Philippe Descamps
Mar 27 at 14:00
add a comment |
There's no one role associated with an instance; rather, the role is associated with a method called by the instance. Try this.
PATH = 'home_drive_'
PLATFORM = 'Linux_'
ITEM = '_PC'
class Credential:
def __init__(self, *, path, platform, **kwargs):
super().__init__(**kwargs)
self.username_file = path + platform
class AXL(Credential):
def __init__(self, *, item, **kwargs):
super().__init__(**kwargs)
self.item = item
# "Private" method used to implement the other phone methods
# You could inline this if you want.
def _phone(self, role):
return self.username_file + role + self.item
def getphone(self):
return self._phone('r')
def writephone(self):
return self._phone('rw')
def statusphone(self):
return self._phone('rwx')
reg1 = AXL(path=PATH, platform=PLATFORM, item=ITEM)
print(reg1.getphone())
print(reg1.writephone())
print(reg1.statusphone())
There's no one role associated with an instance; rather, the role is associated with a method called by the instance. Try this.
PATH = 'home_drive_'
PLATFORM = 'Linux_'
ITEM = '_PC'
class Credential:
def __init__(self, *, path, platform, **kwargs):
super().__init__(**kwargs)
self.username_file = path + platform
class AXL(Credential):
def __init__(self, *, item, **kwargs):
super().__init__(**kwargs)
self.item = item
# "Private" method used to implement the other phone methods
# You could inline this if you want.
def _phone(self, role):
return self.username_file + role + self.item
def getphone(self):
return self._phone('r')
def writephone(self):
return self._phone('rw')
def statusphone(self):
return self._phone('rwx')
reg1 = AXL(path=PATH, platform=PLATFORM, item=ITEM)
print(reg1.getphone())
print(reg1.writephone())
print(reg1.statusphone())
answered Mar 26 at 12:47
chepnerchepner
275k40 gold badges267 silver badges363 bronze badges
275k40 gold badges267 silver badges363 bronze badges
that's working but not sure how I can use it in my real script that I copied here
– Louis-Philippe Descamps
Mar 26 at 15:10
It looks like anything involvingroleshould be a method that builds the path on the fly using arolearugment, rather than being an attribute of an instance. Or, you should have a lot more subclasses, each of which does have a fixed role.
– chepner
Mar 26 at 15:15
Hi, what about doing it like this. thanks
– Louis-Philippe Descamps
Mar 27 at 14:00
add a comment |
that's working but not sure how I can use it in my real script that I copied here
– Louis-Philippe Descamps
Mar 26 at 15:10
It looks like anything involvingroleshould be a method that builds the path on the fly using arolearugment, rather than being an attribute of an instance. Or, you should have a lot more subclasses, each of which does have a fixed role.
– chepner
Mar 26 at 15:15
Hi, what about doing it like this. thanks
– Louis-Philippe Descamps
Mar 27 at 14:00
that's working but not sure how I can use it in my real script that I copied here
– Louis-Philippe Descamps
Mar 26 at 15:10
that's working but not sure how I can use it in my real script that I copied here
– Louis-Philippe Descamps
Mar 26 at 15:10
It looks like anything involving
role should be a method that builds the path on the fly using a role arugment, rather than being an attribute of an instance. Or, you should have a lot more subclasses, each of which does have a fixed role.– chepner
Mar 26 at 15:15
It looks like anything involving
role should be a method that builds the path on the fly using a role arugment, rather than being an attribute of an instance. Or, you should have a lot more subclasses, each of which does have a fixed role.– chepner
Mar 26 at 15:15
Hi, what about doing it like this. thanks
– Louis-Philippe Descamps
Mar 27 at 14:00
Hi, what about doing it like this. thanks
– Louis-Philippe Descamps
Mar 27 at 14:00
add a comment |
super() will let you access the parent class scope. You can access any method from it in the form super().method(args) in python3, with python 2 the format is super(YourClass,self).method(args).
Calling __init__ on the parent for each method doesn't seems to be right from the OOP perspective. You are reinitializing the parent object during its life time. If you want to set role from the parent you can simply use self.role = .... Any method on parent accessing self.role will see the modification.
add a comment |
super() will let you access the parent class scope. You can access any method from it in the form super().method(args) in python3, with python 2 the format is super(YourClass,self).method(args).
Calling __init__ on the parent for each method doesn't seems to be right from the OOP perspective. You are reinitializing the parent object during its life time. If you want to set role from the parent you can simply use self.role = .... Any method on parent accessing self.role will see the modification.
add a comment |
super() will let you access the parent class scope. You can access any method from it in the form super().method(args) in python3, with python 2 the format is super(YourClass,self).method(args).
Calling __init__ on the parent for each method doesn't seems to be right from the OOP perspective. You are reinitializing the parent object during its life time. If you want to set role from the parent you can simply use self.role = .... Any method on parent accessing self.role will see the modification.
super() will let you access the parent class scope. You can access any method from it in the form super().method(args) in python3, with python 2 the format is super(YourClass,self).method(args).
Calling __init__ on the parent for each method doesn't seems to be right from the OOP perspective. You are reinitializing the parent object during its life time. If you want to set role from the parent you can simply use self.role = .... Any method on parent accessing self.role will see the modification.
answered Mar 26 at 13:03
geckosgeckos
1,5481 gold badge13 silver badges26 bronze badges
1,5481 gold badge13 silver badges26 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55340337%2fpassing-argument-from-method-using-super%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If i understand correctly, you can set
self.role = 'r'insideAXL.final.– heemayl
Mar 25 at 14:43
If I understand you correctly, you can't (at least not in any way that conforms to conventions and that will be easy to debug).
roleis required to initialize aCredentialinstance so it must be provided when initializing anAXLinstance.– DeepSpace
Mar 25 at 14:44
It's not clear what your ultimate goal is. Do you want to replace the attribute
username_file(currently initialized in__init__) with a method that computes a value using a given role when called? (Which would convertrolefrom an attribute of an instance to simply an argument tofinal.)– chepner
Mar 25 at 15:02
for example, i would have AXL.getphone, AXL.writephone and AXL.statusphone. getphone's role is read-only (r) writephone's role is read/write (rw) statusphone's role is read/write/execute (rwx) Depending of the role, the credential would return the username/pwd to use thank you
– Louis-Philippe Descamps
Mar 25 at 15:22
@chepner, this is what I'm trying to do repl.it/@louis_philippedescamps/…
– Louis-Philippe Descamps
Mar 26 at 9:17