Python equivalent to Perl's warn/confess/die

David Bolen db3l at fitlinxx.com
Wed May 24 22:29:47 CEST 2000


Andy Lester <andy at petdance.com> writes:

> I looked in the Perl/Python phrasebook and didn't see anything that
> discusses an easy way to write warnings to the screen.
> 
> For instance, in Perl if I wanted to write something to stderr to show
> where in my process I am, I'd say:
> 
>   warn "$n records read";
> 
> Now, I know I can say
> 
>   sys.stderr.write( '%s records read' % n ) 
> 
> But is there a module somewhere that encapsulates that so I don't
> explicitly send it to stderr?

I'm curious - It's my understanding that by definition, 'warn' in Perl
sends its output to stderr, so in reality in both cases you are
explicitly sending the data to stderr, regardless of the command
you've typed.

If you're saying that you don't like writing 'sys.stderr.write'
instead of 'warn', then how about just doing 'warn=sys.stderr.write'
in your script and then go ahead and use 'warn'?  :-)

Perhaps you could clarify just what you are trying to "encapsulate" in
this case?

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list