Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8459 > unrolled thread

Python 3 syntax error question

Started byrzed <rzantow@gmail.com>
First post2011-06-26 13:04 +0000
Last post2011-06-26 16:10 +0100
Articles 9 — 7 participants

Back to article view | Back to comp.lang.python


Contents

  Python 3 syntax error question rzed <rzantow@gmail.com> - 2011-06-26 13:04 +0000
    Re: Python 3 syntax error question steve+comp.lang.python@pearwood.info - 2011-06-27 00:51 +1000
      Re: Python 3 syntax error question rzed <rzantow@gmail.com> - 2011-06-26 15:28 +0000
        Re: Python 3 syntax error question Chris Angelico <rosuav@gmail.com> - 2011-06-27 01:31 +1000
        Re: Python 3 syntax error question Noah Hall <enalicho@gmail.com> - 2011-06-26 16:32 +0100
        Re: Python 3 syntax error question Jerry Hill <malaclypse2@gmail.com> - 2011-06-26 12:50 -0400
        Re: Python 3 syntax error question Terry Reedy <tjreedy@udel.edu> - 2011-06-26 13:31 -0400
    Re: Python 3 syntax error question Peter Otten <__peter__@web.de> - 2011-06-26 16:59 +0200
    Re: Python 3 syntax error question Noah Hall <enalicho@gmail.com> - 2011-06-26 16:10 +0100

#8459 — Python 3 syntax error question

Fromrzed <rzantow@gmail.com>
Date2011-06-26 13:04 +0000
SubjectPython 3 syntax error question
Message-ID<Xns9F105B30356CArzantowgmailcom@74.209.131.13>
I've tried to install PySVG in a Python 3 setting, and I get a few 
errors on the build. Most are easy to fix, but this one I can't 
explain or fix:

<error>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "builders.py", line 12, in <module>
    from pysvg.shape import *
  File "C:\Python32\lib\site-packages\pysvg\shape.py", line 91
    def moveToPoint(self,(x,y)):
                         ^
SyntaxError: invalid syntax 
</error>

The moveToPoint method occurs three times in the file, with identical 
signatures. The other two are not showing up as errors, though since 
they occur later in the file, that may not be indicative. 

I don't see anything erroneous in this line. The syntax error often 
comes from the previous line, but I've moved this method around and 
it has always failed on this line and no other, regardless of what 
went before. 

I'm new to Py3, so maybe there's some obvious thing I'm not seeing 
here. Does anyone have any suggestions?

-- 
rzed

[toc] | [next] | [standalone]


#8461

Fromsteve+comp.lang.python@pearwood.info
Date2011-06-27 00:51 +1000
Message-ID<4e074768$0$29982$c3e8da3$5496439d@news.astraweb.com>
In reply to#8459
rzed wrote:

> I've tried to install PySVG in a Python 3 setting, and I get a few
> errors on the build. Most are easy to fix, but this one I can't
> explain or fix:
> 
> <error>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "builders.py", line 12, in <module>
>     from pysvg.shape import *
>   File "C:\Python32\lib\site-packages\pysvg\shape.py", line 91
>     def moveToPoint(self,(x,y)):
>                          ^
> SyntaxError: invalid syntax
> </error>

Function signatures with automatic tuple-unpacking are no longer allowed in
Python3. So functions or methods like this:

def moveToPoint(self,(x,y)):

have to be re-written with the tuple unpacking moved into the body of the
function, e.g. something like this:

def moveToPoint(self, x_y):
    x, y = x_y


Are you aware that you're trying to install a Python2 library under Python3?


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#8464

Fromrzed <rzantow@gmail.com>
Date2011-06-26 15:28 +0000
Message-ID<Xns9F1073B21B96Frzantowgmailcom@74.209.131.13>
In reply to#8461
steve+comp.lang.python@pearwood.info wrote in
news:4e074768$0$29982$c3e8da3$5496439d@news.astraweb.com: 

> rzed wrote:
> 
>> I've tried to install PySVG in a Python 3 setting, and I get a
>> few errors on the build. Most are easy to fix, but this one I
>> can't explain or fix:
>> 
>> <error>
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>>   File "builders.py", line 12, in <module>
>>     from pysvg.shape import *
>>   File "C:\Python32\lib\site-packages\pysvg\shape.py", line 91
>>     def moveToPoint(self,(x,y)):
>>                          ^
>> SyntaxError: invalid syntax
>> </error>
> 
> Function signatures with automatic tuple-unpacking are no longer
> allowed in Python3. So functions or methods like this:
> 
> def moveToPoint(self,(x,y)):
> 
> have to be re-written with the tuple unpacking moved into the
> body of the function, e.g. something like this:
> 
> def moveToPoint(self, x_y):
>     x, y = x_y
> 
> 
> Are you aware that you're trying to install a Python2 library
> under Python3? 
> 
> 

Thank you all for your responses. Yes, I am aware of the version 
difference, but not of all the implications of that. I will run this 
through 2to3, but even without doing that, there are only about four 
syntax errors, and the others were obvious and easily corrected. 

There does not seem to be a Py3 version of this package. I was hoping 
to try it to see what broke. Well, I found out at least part of that, 
didn't I?

I was not aware of the removal of tuple-unpacking. I expect there was 
some extensive conversation about that. 

As to 2to3, I have to say that:

-def a(b, (c,d)):
+def a(b, xxx_todo_changeme):
+    (c,d) = xxx_todo_changeme

... is not terribly revealing if one is unaware of what about it 
needs changing. I know, I know: RTFM....

-- 
rzed

[toc] | [prev] | [next] | [standalone]


#8465

FromChris Angelico <rosuav@gmail.com>
Date2011-06-27 01:31 +1000
Message-ID<mailman.417.1309102349.1164.python-list@python.org>
In reply to#8464
On Mon, Jun 27, 2011 at 1:28 AM, rzed <rzantow@gmail.com> wrote:
> As to 2to3, I have to say that:
>
> -def a(b, (c,d)):
> +def a(b, xxx_todo_changeme):
> +    (c,d) = xxx_todo_changeme
>
> ... is not terribly revealing if one is unaware of what about it
> needs changing. I know, I know: RTFM....

Sure, but you don't _have_ to look at the diff. Just run it through
2to3 and see how it runs. Never know, it might work direct out of the
box!

ChrisA

[toc] | [prev] | [next] | [standalone]


#8466

FromNoah Hall <enalicho@gmail.com>
Date2011-06-26 16:32 +0100
Message-ID<mailman.418.1309102375.1164.python-list@python.org>
In reply to#8464
On Sun, Jun 26, 2011 at 4:28 PM, rzed <rzantow@gmail.com> wrote:
> steve+comp.lang.python@pearwood.info wrote in
> news:4e074768$0$29982$c3e8da3$5496439d@news.astraweb.com:
>
>> rzed wrote:
>>
>>> I've tried to install PySVG in a Python 3 setting, and I get a
>>> few errors on the build. Most are easy to fix, but this one I
>>> can't explain or fix:
>>>
>>> <error>
>>> Traceback (most recent call last):
>>>   File "<stdin>", line 1, in <module>
>>>   File "builders.py", line 12, in <module>
>>>     from pysvg.shape import *
>>>   File "C:\Python32\lib\site-packages\pysvg\shape.py", line 91
>>>     def moveToPoint(self,(x,y)):
>>>                          ^
>>> SyntaxError: invalid syntax
>>> </error>
>>
>> Function signatures with automatic tuple-unpacking are no longer
>> allowed in Python3. So functions or methods like this:
>>
>> def moveToPoint(self,(x,y)):
>>
>> have to be re-written with the tuple unpacking moved into the
>> body of the function, e.g. something like this:
>>
>> def moveToPoint(self, x_y):
>>     x, y = x_y
>>
>>
>> Are you aware that you're trying to install a Python2 library
>> under Python3?
>>
>>
>
> Thank you all for your responses. Yes, I am aware of the version
> difference, but not of all the implications of that. I will run this
> through 2to3, but even without doing that, there are only about four
> syntax errors, and the others were obvious and easily corrected.
>
> There does not seem to be a Py3 version of this package. I was hoping
> to try it to see what broke. Well, I found out at least part of that,
> didn't I?
>
> I was not aware of the removal of tuple-unpacking. I expect there was
> some extensive conversation about that.
>
> As to 2to3, I have to say that:
>
> -def a(b, (c,d)):
> +def a(b, xxx_todo_changeme):
> +    (c,d) = xxx_todo_changeme
>
> ... is not terribly revealing if one is unaware of what about it
> needs changing. I know, I know: RTFM....

It means delete every line with a '-' and replace them with those next
to the '+'
Of course, if you read the doc, it'll give you lots of different
options, including writing to the file, so all you need to do is
change the variable names.

[toc] | [prev] | [next] | [standalone]


#8470

FromJerry Hill <malaclypse2@gmail.com>
Date2011-06-26 12:50 -0400
Message-ID<mailman.419.1309107054.1164.python-list@python.org>
In reply to#8464
On Sun, Jun 26, 2011 at 11:31 AM, Chris Angelico <rosuav@gmail.com> wrote:
> Sure, but you don't _have_ to look at the diff. Just run it through
> 2to3 and see how it runs. Never know, it might work direct out of the
> box!

This has been my experience, by the way.  I've used a few small pure
python libraries written for python 2.x that don't have 3.x versions,
and they've all worked just fine with just a quick run through the
2to3 process.  I can't speak for larger libraries, or ones with lots
of compiled code, but my experience with 2to3 has been great.

-- 
Jerry

[toc] | [prev] | [next] | [standalone]


#8472

FromTerry Reedy <tjreedy@udel.edu>
Date2011-06-26 13:31 -0400
Message-ID<mailman.421.1309109519.1164.python-list@python.org>
In reply to#8464
On 6/26/2011 11:28 AM, rzed wrote:
> steve+comp.lang.python@pearwood.info wrote in

>> Are you aware that you're trying to install a Python2 library
>> under Python3?

> Thank you all for your responses. Yes, I am aware of the version
> difference, but not of all the implications of that. I will run this
> through 2to3, but even without doing that, there are only about four
> syntax errors, and the others were obvious and easily corrected.

When you are done, I hope you feed results back to author as to how to 
make code run under Py3 without change (the explicit unpacking needed 
for Py3 works in Py2 also) or without further change after 2to3. Then 
encourage author to advertise fact and add Py3 classifier if listed in PyPI.

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#8462

FromPeter Otten <__peter__@web.de>
Date2011-06-26 16:59 +0200
Message-ID<mailman.415.1309100401.1164.python-list@python.org>
In reply to#8459
rzed wrote:

> I've tried to install PySVG in a Python 3 setting, and I get a few
> errors on the build. Most are easy to fix, but this one I can't
> explain or fix:
> 
> <error>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "builders.py", line 12, in <module>
>     from pysvg.shape import *
>   File "C:\Python32\lib\site-packages\pysvg\shape.py", line 91
>     def moveToPoint(self,(x,y)):
>                          ^
> SyntaxError: invalid syntax
> </error>
> 
> The moveToPoint method occurs three times in the file, with identical
> signatures. The other two are not showing up as errors, though since
> they occur later in the file, that may not be indicative.
> 
> I don't see anything erroneous in this line. The syntax error often
> comes from the previous line, but I've moved this method around and
> it has always failed on this line and no other, regardless of what
> went before.
> 
> I'm new to Py3, so maybe there's some obvious thing I'm not seeing
> here. Does anyone have any suggestions?
> 

Quoting

http://docs.python.org/dev/py3k/whatsnew/3.0.html#removed-syntax

"""
You can no longer write def foo(a, (b, c)): .... Use def foo(a, b_c): b, c = 
b_c instead.
"""

If there isn't a Python 3 version of PySVG you can try to run it through

http://docs.python.org/dev/py3k/library/2to3.html#to3-reference

to make the easy changes.

[toc] | [prev] | [next] | [standalone]


#8463

FromNoah Hall <enalicho@gmail.com>
Date2011-06-26 16:10 +0100
Message-ID<mailman.416.1309101045.1164.python-list@python.org>
In reply to#8459
On Sun, Jun 26, 2011 at 2:04 PM, rzed <rzantow@gmail.com> wrote:
> I've tried to install PySVG in a Python 3 setting, and I get a few
> errors on the build. Most are easy to fix, but this one I can't
> explain or fix:
>
> <error>
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File "builders.py", line 12, in <module>
>    from pysvg.shape import *
>  File "C:\Python32\lib\site-packages\pysvg\shape.py", line 91
>    def moveToPoint(self,(x,y)):
>                         ^
> SyntaxError: invalid syntax
> </error>
>
> The moveToPoint method occurs three times in the file, with identical
> signatures. The other two are not showing up as errors, though since
> they occur later in the file, that may not be indicative.
>
> I don't see anything erroneous in this line. The syntax error often
> comes from the previous line, but I've moved this method around and
> it has always failed on this line and no other, regardless of what
> went before.
>
> I'm new to Py3, so maybe there's some obvious thing I'm not seeing
> here. Does anyone have any suggestions?

Did you run it through 2to3? When I run
def a(b, (c,d)):
    pass
through 2to3, it tells me what I need to change.

-def a(b, (c,d)):
+def a(b, xxx_todo_changeme):
+    (c,d) = xxx_todo_changeme

(which is what Steven said)

If you haven't used 2to3, I suggest you use it.

HTH.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web