[ros-users] [Discourse.ros.org] [Client Libraries] Python3 and strings

Asmodehn ros.discourse at gmail.com
Tue Aug 8 02:16:40 UTC 2017



It also says : 

- Primitive Type: string
- Serialization: ascii string (4)
- C++: std::string
- Python: **str**

and

- Primitive Type: uint8[]
- Serialization: uint32 length prefix
- C++: std::vector
- Python: **bytes**


Also in python3 both encoding and decoding are automatic, based on the platform you are running on, provided you use the right type (bytes or str).

If two platforms use different encodings for two nodes communicating, then messages will probably arrived garbled, if we intend to send a string.

On the other hand, if we do not send a string with an encoding, then we are sending **bytes**, just like for a `uint8[]` field.

- Is `string` the same as `uint8[]` ? (and Python type should be **bytes**)
- OR should ROS enforce some unicode encoding for string ? (and Python type can be **str**)

In any instance it seems the wiki page should separately list Python2 and Python3 to avoid confusion...





---
[Visit Topic](https://discourse.ros.org/t/python3-and-strings/2392/3) or reply to this email to respond.




More information about the ros-users mailing list