4

I'm trying to write a very simple address book webapp in Python. I'm new to Python but have had a fair amount of time writing in Perl, I want to know what is the equivalent to Perl's warn function in Python 3.6.

wyz23x2
  • 298
  • 4
  • 16
  • 1
    Have you made any attempt to figure this out on your own? The Python documentation is quite good. – Mad Physicist Dec 20 '17 at 23:15
  • 1
    From [Perl docs](http://perldoc.perl.org/functions/warn.html) "Prints the value of LIST to STDERR. If the last element of LIST does not end in a newline". [First link](https://stackoverflow.com/questions/5574702/how-to-print-to-stderr-in-python) after googling "python Prints the value of LIST to STDERR". –  Dec 20 '17 at 23:19

1 Answers1

5

If you are looking for the equivalent of raising warnings you can use pythons warnings module like so:

from warnings import warn

warn('Your message here', Warning)

This will display __main__:1: Warning: my message here on stderr.

If you are looking for the equivalent of raising errors you can use pythons Exception class like so:

raise Exception('Your message here')

This will display Exception: Your message here on stderr.

mattjegan
  • 2,724
  • 1
  • 26
  • 37