0

I would like to print just the warning messages in python rather than the message and the code similar to what has been asked in this question: Python: Print only the message on warnings

The solutions to the above question suggest that one can replace the implementation of the warnings.showwarnings() function with a implementation of their own (monkeypatching) to achieve that goal.

Would it not be easier to just write to stderr instead? Are there reasons to choose the warnings module over simply writing to stderr?

Community
  • 1
  • 1
Slothworks
  • 1,083
  • 14
  • 18

1 Answers1

1

Configurability, and putting the choice of when and where warnings generated by third-party libraries are shown into the hands of the developer using those libraries.

If this is your own application and you don't expect your code to be used anywhere else, by all means just write to stderr. But take into account that if you later changed your mind you then have to alter all locations that write to stderr rather than change the warnings configuration.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343