Convert Python Long to String

23 11 2009

You want to output a numerical value to a file in your python script.

However you get an error:

>>>data=123246
>>>fileOut.write(data)
>>>TypeError: argument 1 must be string or read-only character buffer, not int

No python is not wrong but the solution is very simple. cast it to string:

>>>fileOut.write(str(data))

How easy is that?

Go python!

Little Nibbles

About these ads

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.

%d bloggers like this: