CGI Proplem displaying image

Georgy no.mail at available.net
Thu May 13 05:51:41 EDT 2004


"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





More information about the Python-list mailing list