CGI -- generating images -- \x0A always added!
John Hazen
python-list at hazen.net
Wed Sep 10 04:00:48 EDT 2003
Before the program exits, you can set sys.stdout.softspace to 0, and that
will prevent the pending newline from printing.
In the interactive mode:
>>> print "foo",
foo
>>> # note the extra newline, so the prompt is on its own line.
...
>>> print "foo",;sys.stdout.softspace = 0
foo>>> # no newline
But the way which is probably most appropriate for dealing with
binary data (it should also make the '-u' unneccessary) is:
>>> sys.stdout.write("foo")
foo>>> # no newline...
HTH-
John
(john AT <my domain (see from address)>)
On Wed, Sep 10, 2003 at 03:05:51AM +0000, M-a-S wrote:
> Hi All,
>
> I'm trying to use Python for generating (or copying) images.
> The environment is Python 2.3/Apache 2.0.43/Windows XP.
> I couldn't make Apache use mod_python (anybody can help?
> Apache complains "The requested operation has failed"
> if I add LoadModule python_module modules/mod_python.so)
> so I use the CGI mechanism. This is the sample:
>
> #!C:\Apps\Python\python.exe -u
>
> img = open( 'a.gif', 'rb' ) # OK, don't make the image, just use the file
> if img:
> data = img.read()
> img.close()
>
> print "Content-type: image/gif"
> print
>
> print data,
>
> # EOF
>
> Everything's good, and '-u' helps not to add '\x0D' for each '\x0A'
> inside the data. BUT it seems that the last print ALWAYS adds LF
> '\x0A' in spite of the final comma. How can I fix that? Thank you.
More information about the Python-list
mailing list