Print to console?

100 views
Skip to first unread message

jlist9

unread,
Nov 8, 2009, 12:20:49 PM11/8/09
to we...@googlegroups.com
Now that web.py uses return instead of print, is it possible to use the print
statement to print to console for debugging?

Angelo Gladding

unread,
Nov 8, 2009, 12:58:38 PM11/8/09
to we...@googlegroups.com
Did you try it?


On Sun, Nov 8, 2009 at 9:20 AM, jlist9 <jli...@gmail.com> wrote:

Now that web.py uses return instead of print, is it possible to use the print
statement to print to console for debugging?





--
Angelo Gladding
ang...@gladding.name
http://angelo.gladding.name/
E69E 47E8 5C3A 96E5 C70F
D931 F35C ACBA 6F39 9611

jlist9

unread,
Nov 8, 2009, 1:17:20 PM11/8/09
to we...@googlegroups.com
Oops. Sorry, it works well. I must have tried it on a box with an
earlier version
installed.

xrfang

unread,
Nov 8, 2009, 6:52:44 PM11/8/09
to web.py
Well I have not tried it yet :) But I thought there is a web.debug() I
see somewhere in the doc. Does it still work if web.py is running as
FCGI? I doubt it.

On Nov 9, 1:58 am, Angelo Gladding <ang...@gladding.name> wrote:
> Did you try it?
>
> On Sun, Nov 8, 2009 at 9:20 AM, jlist9 <jli...@gmail.com> wrote:
>
> > Now that web.py uses return instead of print, is it possible to use the
> > print
> > statement to print to console for debugging?
>
> --
> Angelo Gladding
> ang...@gladding.namehttp://angelo.gladding.name/

Graham Dumpleton

unread,
Nov 8, 2009, 10:17:35 PM11/8/09
to web.py
On Nov 9, 4:20 am, jlist9 <jli...@gmail.com> wrote:
> Now that web.py uses return instead of print, is it possible to use the print
> statement to print to console for debugging?

If you mean unadorned print such as:

print 'hi'

then if you want to be a portable WSGI application the answer is no,
as WSGI adapters for CGI don't properly protect the stdout used by CGI
to communicate with the server and so by doing so you will screw with
the response from the application.

To try to encourage people to write portable WSGI applications,
mod_wsgi also places artificial restrictions on using stdin/stdout by
default. Because though most people couldn't be bother fixing code so
as to not use 'print' and instead direct it to 'stderr', that
restriction will be removed in mod_wsgi 3.0 however.

Read:

http://blog.dscpl.com.au/2009/04/wsgi-and-printing-to-standard-output.html

In summary, use 'print' if you want, but use:

import sys
print >> sys.stderr, 'hi'

as better anyway.

Graham

jlist9

unread,
Nov 8, 2009, 11:20:08 PM11/8/09
to we...@googlegroups.com
Thanks for explaining!
Reply all
Reply to author
Forward
0 new messages