0
Broken ,,self'' argument in Python
This glitch was upsetting me for quite some time. If I call an instance of an object in one of my games and then any of it's functions, I have to write the object's name as the first parameter, because Python refuses to fill that in automatically. That alone is upsetting me a bit, because everywhere I look they say ,,Python will fill that in automatically''. Then why THE HELL I have to fill that in manually?! But that doesn't upset me as much as this: Sometimes I have to write in the object's name, and sometimes I don't. WTH? Please explain me. Python used - 3.6.2 IDE used - Pydroid3
8 Antworten
+ 3
There's a 99% chance that you're doing something wrong, but that's difficult to tell without seeing your code. I'm positive that "your" python works just the same as everyone else's version of python
+ 2
Why would you do that?
+ 1
Well, then don't do it 👍
+ 1
I never experienced that python switches around in any way. It always needs to look like this:
class Bread():
def slice(self, slices): # defined with two parameters
print(slices)
b = Bread()
b.slice(5) # called with one parameter
0
It tends to occur when I remove the ,,self'' and then I put it back in
0
I just did it when experimenting around with it and noticed that that actually broke it
0
I am OK with having to write the name in. But I am not OK that it tends to switch around like this.
0
All my codes are defined like this and it just switches when I modify the definition. And then I am stuck with the write the name everywhere thing, unless I redefine all the methods