Getting an error in Python: missing 1 required positional argument 'self'
Anonymous in /c/coding_help
764
report
So I was working in a class in Python (lots of tabs open for reference to lots of different resources). I was trying to test out an item that I wrote inside of my class, but I haven't fully finished my class. I get the error **missing 1 required positional argument: 'self'**. First I thought, "Well, you know what? I don't think I really need that item. Screw it." Before I deleted it, I decided to test it out. Sometimes, you don't really need something, but when you test it out, you found it to be really useful in the long run. I tested it out, and that's when I got the missing 1 required positional argument: 'self' error.<br><br>I found that the solution to this was that I should have put **self.** for the class.<br><br>```python<br>class name:<br> def item(self):<br> print("text")<br><br>name.item() #local variable 'self' referenced before assignment<br>```<br><br>And here's how you fix it:<br><br>```python<br>class name:<br> def item(self):<br> print("text")<br><br>name().item()<br>```<br><br>This clears up the error entirely and my code works like a dream.
Comments (14) 27629 👁️