I has to use repr to convert in this string: ÿØÿà\x00\x10JFIF?<br /><br />On Oct 5, 2010 8:03pm, MRAB <python@mrabarnett.plus.com> wrote:<br />> On 05/10/2010 23:50, hidura@gmail.com wrote:<br />> <br />> <br />> I did but the mistake is: Error interpreting JPEG image file (Not a JPEG<br />> <br />> file: starts with 0x5c 0x6e)<br />> <br />> I think the problem is maybe in the binary code here is:<br />> <br />> [snip]<br />> <br />> <br />> <br />> Sorry for the last send.<br />> <br />>  > On Oct 5, 2010 6:18pm, "Jonas H." jonas@lophus.org> wrote:<br />> <br />>  > > On 10/05/2010 11:11 PM, hidura@gmail.com wrote:<br />> <br />>  > ><br />> <br />>  > ><br />> <br />>  > > Hello, how i can save a binary file, i read in the manual in the IO<br />> <br />> area<br />> <br />>  > ><br />> <br />>  > > but doesn' t show how to save it.<br />> <br />>  > ><br />> <br />>  > > Here is the code what i am using:<br />> <br />>  > ><br />> <br />>  > > s = open('/home/hidura/test.jpeg', 'wb')<br />> <br />>  > ><br />> <br />>  > > s.write(str.encode(formFields[5]))<br />> <br />>  > ><br />> <br />>  > > s.close()<br />> <br />>  > ><br />> <br />>  > ><br />> <br />>  > ><br />> <br />>  > ><br />> <br />>  > > So where's the problem? That code should work. Anyway, you want to<br />> <br />> have a look at with-statements.<br />> <br />>  > ><br />> <br />> <br />> Why are you encoding it? A JPEG file should contain the binary data,<br />> <br />> not a textual encoding of its bytes. The error message you got said<br />> <br />> that the contents of the file started with a backslash.<br />> <br />> <br />> <br />> If you print out, say, repr(str[ : 10]) you should get something like<br />> <br />> 'ÿØÿà\x00\x10JFIF'.<br />> <br />> <br />> <br />> Try this instead:<br />> <br />> <br />> <br />> s = open('/home/hidura/test.jpeg', 'wb')<br />> <br />> s.write(str)<br />> <br />> s.close()<br />> <br />> <br />> <br />> Incidentally, 'str' is a bad name for a variable because it's the name<br />> <br />> of the built-in string type.<br />> <br />> -- <br />> <br />> http://mail.python.org/mailman/listinfo/python-list<br />>