Reputation: 43
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?
Upvotes: 0
Views: 64
Reputation: 2524
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.
Upvotes: 1