0

I made this code in PYTHON 2.7.17:

class prt(object):
    def _print(self, x):
        self.x = x
        print x
    def Write_turtle(self, shape, move=False, text_of_show, font=('Arial', 16, 'bold')):
        try:
            x.shape(shape)
            x.write(text_of_show, move, font)
        except:
            from turtle import *
            x = Turtle()
            x.shape(shape)
            x.write(text_of_show, move, font)

And it gave me this error at the end of line 5:

SyntaxError: non-default argument follows default argument

Can anyone help me? Thank you very much.

  • Does this answer your question? [Python function arguments with default arguments](https://stackoverflow.com/questions/54490349/python-function-arguments-with-default-arguments) – Tomerikoo May 18 '20 at 15:06

1 Answers1

1

in your definition of Write_turtle the parameters move and font have default parameters. As the error message tells you, you have to put them at the end of the parameter list, e.g.:

def Write_turtle(self, shape, text_of_show, move=False, font=('Arial', 16, 'bold'))

The reason is, that these parameters are optional. If you do not set them, the default value is used. Because text_of_show has no default parameter, you always have to set it. This also implies, that you have to give all parameters before it a value. Therefore the default value for move is obsolete. If you call e.g.

Write_turtle((20, 10), True)

the interpreter would not know if the True is the value for move or for text_of_show. If you rearrange the parameters correctly as mentioned above you can call:

Write_turtle((20, 10), True)
Write_turtle((20, 10), False, True)

The first version sets move=False (its default value) the second one sets move=True.

For more information have a look at this!

Thomas Wilde
  • 801
  • 7
  • 15
  • Thanks, but now I recive this error: SyntaxError: import * only allowed at module level (, line 6) – Sebastian Chetroni May 18 '20 at 16:22
  • Now the problem is in the line: `from turtle import *` You should replace the `*` by the methods you really need. `import *` is only allowed at "top" level of your file structure. Another solution could be to move `from turtle import *` to the top of your file. [Have a look at this post!](https://stackoverflow.com/questions/3571514/python-why-should-from-module-import-be-prohibited) – Thomas Wilde May 19 '20 at 09:32