Python equivalent to Perl's warn/confess/die
greg Landrum
greglandrum at earthlink.net
Wed May 24 10:30:10 EDT 2000
Andy Lester wrote:
>
> 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?
You could write your own. Put this in a file called warn.py which lives
somewhere in your PYTHONPATH:
import sys
__warningDest = sys.stderr
def warn(msg):
__warningDest.write(msg + '\n')
then you can do:
from warn import warn
warn('beware the Jabberwock')
-greg
--
greg Landrum (greglandrum at earthlink.net)
Software Carpenter/Computational Chemist
More information about the Python-list
mailing list