Hi, Gandia Augusto,
in contrast to cPython 2.7, IronPython does not have byte-strings. This is due
to .NET - strings in .NET are always unicode, they're the same type there. And
to convert an Unicode string to a byte array, you will always need an encoding.
The situation wr/t strings is much more similar to cPython 3.x, where str is
always unicode.
Whether this concrete occurrence can be considered a bug in IronPython (it
should be able to cope with it), I don't know.
On the other hand, a simple reproduction fails on my machine:
IronPython 2.7.5 (2.7.5.0) on .NET 4.0.30319.42000 (32-bit)
Type "help", "copyright", "credits" or "license" for more information.
>>> bytearray
<type 'bytearray'>
>>> bytearray('hallo')
bytearray(b'hallo')
>>> bytearray('halloäöü')
bytearray(b'hallo\xe4\xf6\xfc')
>>>
So there must be something more (which IronPython version are you using?)
However, you should be able to work around the problem by specifying an
encoding:
>>> bytearray('halloäöü', "latin-1")
bytearray(b'hallo\xe4\xf6\xfc')
>>> bytearray('halloäöü', "utf-8")
bytearray(b'hallo\xc3\xa4\xc3\xb6\xc3\xbc')
So your code could look something like
...
else:
if type(signalValue) is bytearray:
sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
if type(signalValue) is unicode:
signalValue=bytearray(signalValue, 'ascii') # use whatever encoding
is appropriate
sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
if type(signalValue) is str:
signalValue=bytearray(signalValue)
sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
...
Just make sure that you check for unicode before you check for str, as on
Ironpython:
>>> unicode is str
True
Best regards
Markus Schaber
CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions
________________________________
3S-Smart Software Solutions GmbH
Dipl.-Inf. Markus Schaber | Product Development Core Technology
Memminger Str. 151 | 87439 Kempten | Germany
Tel. +49-831-54031-979 | Fax +49-831-54031-50
E-Mail: [email protected]<mailto:[email protected]> | Web:
codesys.com<http://www.codesys.com> | CODESYS store:
store.codesys.com<http://store.codesys.com>
CODESYS forum: forum.codesys.com<http://forum.codesys.com>
Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | Trade
register: Kempten HRB 6186 | Tax ID No.: DE 167014915
________________________________
This e-mail may contain confidential and/or privileged information. If you are
not the intended recipient (or have received
this e-mail in error) please notify the sender immediately and destroy this
e-mail. Any unauthorised copying, disclosure
or distribution of the material in this e-mail is strictly forbidden.
Von: Ironpython-users
[mailto:[email protected]] Im Auftrag
von Gandia Augusto
Gesendet: Donnerstag, 30. Juli 2015 09:51
An: [email protected]
Betreff: [Ironpython-users] question
In this function:
def simxWriteStringStream(clientID, signalName, signalValue, operationMode):
'''
Please have a look at the function description/documentation in the V-REP
user manual
'''
sigV=signalValue
if sys.version_info[0] == 3:
if type(signalName) is str:
signalName=signalName.encode('utf-8')
if type(signalValue) is bytearray:
sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
if type(signalValue) is str:
signalValue=signalValue.encode('utf-8')
sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
else:
if type(signalValue) is bytearray:
sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
if type(signalValue) is str:
signalValue=bytearray(signalValue)#<=============================================================HERE
IS WHERE I GET THE ERROR
sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
sigV=ct.cast(sigV,ct.POINTER(ct.c_ubyte)) # IronPython needs this
return c_WriteStringStream(clientID, signalName, sigV, len(signalValue),
operationMode)
The error I get is :
Program started
Connected to remote API server
Runtime error (TypeErrorException): unicode argument without an encoding
Traceback:
line 1052, in simxWriteStringStream, "C:\Program Files
(x86)\V-REP3\V-REP_PRO_EDU\programming\remoteApiBindings\python\python\vrep.py"
line 70, in script
Any idea of what this could be?
_______________________________________________
Ironpython-users mailing list
[email protected]
https://mail.python.org/mailman/listinfo/ironpython-users