Python 3 support

Requests or suggestions for new features
Post Reply
Pierre
Posts: 10
Joined: 24 Nov 2014, 16:46

Python 3 support

Post by Pierre »

Hi,

I was wondering if the remote API of V-REP will be compatible with Python 3?

There seems to be issue with the string passed as argument. When using this decorator wrapping v-rep calls it seems to work:

Code: Select all

def py3compatible(f):
    if sys.version_info >= (3,0):
        def wrapped_f(*args, **kwargs):
            args = [tbs(a) if isinstance(a, str) else a for a in args]
            kwargs = {k: tbs(v) if isinstance(v, str) else v for k, v in kwargs.items()}

            return f(*args, **kwargs)

        return wrapped_f
    else:
        return f
Cheers,
Pierre

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: Python 3 support

Post by coppelia »

Hello Pierre,

from our experience most users still use Python 2. We haven't really tested it with Python 3. Did you experience other problems except what you mentioned with strings?
Thanks for the code by the way.

Cheers

Pierre
Posts: 10
Joined: 24 Nov 2014, 16:46

Re: Python 3 support

Post by Pierre »

I haven't done much test but as far as I know that was this only problem. I let you know if I find anything else.

BTW I'm not sure the code I post is the best way to solve this issue, but it works though :-)

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: Python 3 support

Post by coppelia »

Actually, the simplest would probably be to simply prefix each string provided to the remote API functions with a 'b':

Code: Select all

'This is a string' --> b'This is a string'
Cheers

Pierre
Posts: 10
Joined: 24 Nov 2014, 16:46

Re: Python 3 support

Post by Pierre »

Yes exactly, that's pretty much what the decorator is doing. I forgot to add the other function:

Code: Select all

def tbs(str):
    return bytes(str, 'ascii')

Post Reply