writing numbers in binary file

2010-05-31 Thread eskandari
Hi, I am a newbie in python. I have an data.pickle file which is serialized form of an array of strings, I want to write their offsets in another binary file, so an C++ program can read and analyse them. But when I try to write offset (number) in binary file, it raise exception below in line

Re: writing numbers in binary file

2010-05-31 Thread MRAB
eskandari wrote: Hi, I am a newbie in python. I have an data.pickle file which is serialized form of an array of strings, I want to write their offsets in another binary file, so an C++ program can read and analyse them. But when I try to write offset (number) in binary file, it raise exception

Re: writing numbers in binary file

2010-05-31 Thread Tim Chase
On 05/31/2010 10:56 AM, eskandari wrote: But when I try to write offset (number) in binary file, it raise exception below in line offsetfile.write(offset) TypeError: argument 1 must be string or read-only buffer, not int I search the internet, find that all suggest converting number to string

Re: writing numbers in binary file

2010-05-31 Thread eskandari
On May 31, 12:30 pm, MRAB pyt...@mrabarnett.plus.com wrote: eskandari wrote: Hi, I am a newbie in python. I have an data.pickle file which is serialized form of an array of strings, I want to write their offsets in another binary file, so an C++ program can read and analyse them. But

Re: writing numbers in binary file

2010-05-31 Thread Terry Reedy
On 5/31/2010 12:43 PM, eskandari wrote: On May 31, 12:30 pm, MRABpyt...@mrabarnett.plus.com wrote: eskandari wrote: Use the 'struct' module to convert the int to a bytestring, and remember to open the file as a binary file. Thanks alot, I have an question, if I do so, Will the second

Re: writing numbers in binary file

2010-05-31 Thread Dave Angel
eskandari wrote: On May 31, 12:30 pm, MRAB pyt...@mrabarnett.plus.com wrote: eskandari wrote: Hi, I am a newbie in python. I have an data.pickle file which is serialized form of an array of strings, I want to write their offsets in another binary file, so an C++ program can read and