CGI Proplem displaying image

matthiasjanes matthiasjanes at gmx.net
Sun May 16 12:03:17 EDT 2004


"Georgy" <no.mail at available.net> wrote in message news:<NyHoc.43027$jU.2411174 at twister.southeast.rr.com>...
> "matthiasjanes" <matthiasjanes at gmx.net> wrote in message news:d588131f.0405122202.5ba4d205 at posting.google.com...
> 
> | Do I have to use the 'sys.stdout.write( something )'
> |
> | or is it also good enough to use 'print (something)'
> 
> Yes, "print something" will be quite safe here, although 'print' adds a newline mark
> or a blank (if you end 'print' with a comma) to the output and sometimes it can show
> on the generated pages. But if you used 'print' for making binary files e.g. images,
> that could ruin the output, so it's usually easier to use sys.stdout.write and not to
> think about this problem. Please note also, that on Windows, both of the ways can
> translate '\n' into '\r\n' so it may be necessary to switch stdout to binary mode, with
> this code, for example:
> try:
>   import msvcrt,os
>   msvcrt.setmode( 1, os.O_BINARY ) # 1 = stdout; use 0 for stdin
> except ImportError:
>   pass
> 
> Georgy


thanks to everyone so far.

Matthias Janes



More information about the Python-list mailing list