2

I have a code using "PyOPC" library (https://github.com/ibh-systems/pyopc). I fixed all the print statements by adding () at the starting and ending.

But when I install the library, I am getting more errors.

Such as:

  File "c:\anaconda3\lib\site-packages\PyOPC-0.1-py3.7.egg\PyOPC\servers\esdsrv.py", line 90
    def Read(self,(IPH,inOptions,outOptions)):
                  ^
SyntaxError: invalid syntax



  File "c:\anaconda3\lib\site-packages\PyOPC-0.1-py3.7.egg\PyOPC\utils.py", line 313
    def print_options((ilist,Options)):
                      ^
SyntaxError: invalid syntax


  File "c:\anaconda3\lib\site-packages\PyOPC-0.1-py3.7.egg\PyOPC\XDAClient.py", line 46
    except ZSI.FaultException, z:
                             ^
SyntaxError: invalid syntax


  File "c:\anaconda3\lib\site-packages\PyOPC-0.1-py3.7.egg\PyOPC\OPCContainers.py", line 257
    raise AttributeError,'Unknown complex type %s for filling'%buf
                        ^
SyntaxError: invalid syntax

Any easy way to fix them? I listed down four main errors, can someone tell me the correct syntax in Python3?

1
  • Were you able to successful convert it over to Python3? Of course, it comes with the ZSI and other libraries that need conversion as well. Commented Aug 9, 2022 at 16:54

3 Answers 3

3

Parameter unpacking has been removed... things like

def foo(x, (y, z)):
    ...

should be changed to

def foo(x, _yz):
    (y, z) = _yz
    ...
Sign up to request clarification or add additional context in comments.

Comments

2

This online tool may help https://www.pythonconverter.com/ which is based on https://docs.python.org/2/library/2to3.html

Edit:

Some Changes

1) print function syntax has been changed from print "Message" to print("Message")
2) xrange is replaced with range
3) Exception raising syntax was raise IOError, "file error" is now raise IOError("file error")
4) Exception Handling was

except NameError, err:
    print err, '--> our error message'

is now

except NameError as err:
    print(err, '--> our error message')

5) my_generator.next() is replaced with next(my_generator)
6) input() now always returns a string

more changes can be found on https://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html

Comments

1
def Read(self,IPH_and_inOptions_and_outOptions):
except ZSI.FaultException as z:
raise AttributeError('Unknown complex type %s for filling'%buf)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.