Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Syntax difference with python

Hello,

I'm trying to do a tricky function that requires a unknown number or regular argument, some default keywords argument and any number of other keyword argument.

In python, this code works:

def addplot_coordinates(*args, plus_option=False, **kwargs):
    pass

But it doesn't work with sage:

sage: def addplot_coordinates(*args, plus_option=False, **kwargs):
....:     pass
  File "<ipython-input-1-dace1b5103c9>", line 1
    def addplot_coordinates(*args, plus_option=False, **kwargs):
                                             ^
SyntaxError: invalid syntax

I naively though that any correct python code would work with sage. I found here* that there is some «minimal syntax difference», and searching «sage python syntax difference» on a search engine does not give relevant results.

Is there a document listing all the things someone coming from python should be careful about ? Can someone give me a pointer to such a document ?

Thank you for your time.

[*] I can't make a link, I meant this page /question/8528/sage-vs-pure-python/ on this forum.

Syntax difference with python

Hello,

I'm trying to do a tricky function that requires a unknown number or regular argument, some default keywords argument and any number of other keyword argument.

In python, this code works:

def addplot_coordinates(*args, plus_option=False, **kwargs):
    pass

But it doesn't work with sage:

sage: def addplot_coordinates(*args, plus_option=False, **kwargs):
....:     pass
  File "<ipython-input-1-dace1b5103c9>", line 1
    def addplot_coordinates(*args, plus_option=False, **kwargs):
                                             ^
SyntaxError: invalid syntax

I naively though that any correct python code would work with sage. I found here* that there is some «minimal syntax difference», and searching «sage python syntax difference» on a search engine does not give relevant results.

Is there a document listing all the things someone coming from python should be careful about ? Can someone give me a pointer to such a document ?

Thank you for your time.

[*] I can't make a link, I meant this page /question/8528/sage-vs-pure-python/ on this forum.

Syntax difference differences with python

Hello,

I'm trying to do a tricky function that requires a unknown number or regular argument, some default keywords argument and any number of other keyword argument.

In python, this code works:

def addplot_coordinates(*args, plus_option=False, **kwargs):
    pass

But it doesn't work with sage:

sage: def addplot_coordinates(*args, plus_option=False, **kwargs):
....:     pass
  File "<ipython-input-1-dace1b5103c9>", line 1
    def addplot_coordinates(*args, plus_option=False, **kwargs):
                                             ^
SyntaxError: invalid syntax

I naively though that any correct python code would work with sage. I found here* that there is some «minimal syntax difference», and searching «sage python syntax difference» on a search engine does not give relevant results.

Is there a document listing all the things someone coming from python should be careful about ? Can someone give me a pointer to such a document ?

Thank you for your time.

[*] I can't make a link, I meant this page /question/8528/sage-vs-pure-python/ on this forum.