0

So, I'm pretty new with turtle, and I was going to make some text, but when I use this function;

    turto1=turtle.Turtle
    turto2=turtle.Turtle
    def spuper():
        turto1.penup()
        turto2.penup()
        turto1.goto(-150,40)
        turto2.goto(-130,40)

I get this error:

    TypeError: penup() missing 1 required 
    positional argument: 'self'

I'm not sure why this happens, and I'm pretty sure the penup() command doesn't have any arguments. Does anyone know what I did wrong?

Nick
  • 43
  • 2
  • 8
  • 1
    `turtle.Turtle()` to instantiate a Turtle (what a phrase) - use parentheses ... turtle.Turtle is the class, not an instance of it – joel Aug 10 '18 at 22:04
  • Possible duplicate of [TypeError: Missing 1 required positional argument: 'self'](https://stackoverflow.com/questions/17534345/typeerror-missing-1-required-positional-argument-self) – Jeff B Aug 10 '18 at 22:31

1 Answers1

1

Change both turtle.Turtle to turtle.Turtle(). Without the () you're assigning the class itself to the variable. Meaning that when you try to call methods on it, the first argument, an instance of the class, won't be implicitly passed to the method. This means that you'll either have to explicitly pass in an instance (turtle.Turtle.penup(aTurtleInstanceThatYouDefinedElsewhere)), or the method call will be treated as a static method, which will cause the error to be thrown if it is not defined as a static method. With the () you're creating an instance of the class and assigning it to the variable. Meaning that when you call a method on it, you will implicitly pass the instance itself to the function as the first argument.

That's the one argument that turto1.penup() is looking for. The instance that it's being called on.

mypetlion
  • 2,415
  • 5
  • 18
  • 22