Static cast equivalent in python

My problem is the following:

I am using ROS and I am currently trying to read values from a PointCloud of a Kinect sensor. The values are of type PointCloud2 and holds the data of the PointCloud and is of type uint8[].

In my project I am currently using python and I have successfully registered and retrieved the data. My issue is that when trying to retrieve them python parses the uint8[] array as strings.

The current part of the script where I have the problem is the follwowing:

def PointCloud(self, PointCloud2):
        for x in
            print x

I know that in c++ I can do something like

 std::cout << static_cast< int >( u );

To get the value of the unsigned integer. Is there a static cast equivalent to python?

In my case print x outputs ASCII characters. How could I retrieve the int value of that?




Use struct.unpack to get the integer value encoded by the binary data in x.

print struct.unpack("!I", x)

(I'm assuming x contains a 4-byte integer in network byte order; consult the documentation for the struct module if you need a format other than !I.)

Update: I missed that you have an array of unsigned bytes; in that case, use

struct.unpack("B", x)

Need Your Help

WCF - Custom Credentials & Security Tokens

wcf servicebehavior

I'm fairly new to WCF development and have run into a couple problems whilst learning the framework. I have a service api which must support both REST &amp; SOAP. So far this has been easy to imple...

BroadcastReceiver for ACTION_MEDIA_BUTTON not working

java android android-intent broadcastreceiver

I am writing an Android application for version 4.0.3 (ICS) of the Android OS. The issue is that I am not getting the output from my Log.d() in the onReceive() method of the BroadcastReceiver which...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.