-1

I know that in order for my function def get_moveup(self) to call my def get_position(self) function, I do self.get_position(). When I try executing my def get_moveup(self) by using knobA.get_moveup() I keep getting TypeError: get_moveup() missing 1 required positional argument: 'self' How would I fix this?

class knobA(knob):
    def __init__(self, position, moveup, movedown, moveleft, moveright):
        super().__init__()
        self.position = position
        self.moveup = moveup
        self.movedown = movedown
        self.moveleft = moveleft 
        self.moveright = moveright 
    
    def get_position(self):
        print("G0 X50 Y50 Z50 \r\n")

    def get_moveup(self):
        self.get_position()
    
    def get_movedown(self):
        return self.movedown
    
    def get_moveleft(self):
        return self.moveleft 
    
    def get_moveright(self):
        return self.moveright
quamrana
  • 37,849
  • 12
  • 53
  • 71
Dylan Sun
  • 13
  • 2
  • What were you expecting `knobA.get_moveup()` to return? – Scott Hunter Jun 28 '21 at 19:00
  • Does this answer your question? [TypeError: Missing 1 required positional argument: 'self'](https://stackoverflow.com/questions/17534345/typeerror-missing-1-required-positional-argument-self) – Pranav Hosangadi Jun 28 '21 at 19:00
  • Why does `get_moveup` call `get_position` instead of returning `self.movup`, and why does `get_position` print a hard-coded string instead of returning `self.position`? – chepner Jun 28 '21 at 20:09
  • @chepner: I think that's a question for another day. The OP will get there, but one focused question at a time. – quamrana Jun 28 '21 at 20:24
  • @chepner All my functions `get_moveup` , `get_movedown` , etc will call the `get_position ` function first. `get_position` will have 5 lines of GCode(not just the 1 line shown in my example) that will be passed to a command function to move the xyz axis of a 3d printer. So instead of having to write 5 lines of GCode for each function `get_moveup` , `get_movedown` etc., I just have to call the function `get_position`. – Dylan Sun Jun 29 '21 at 14:51

2 Answers2

2

You meant to make an instance of class knobA:

k = knobA(...)  # suitable parameters elided
k.get_moveup()
quamrana
  • 37,849
  • 12
  • 53
  • 71
0

Before accessing any properties of the class, you must create an object of that class:

knob = knobA(parameters)
k.get_moveup()

That should help you

Kookies
  • 75
  • 10