jkeirstead
jkeirstead

Reputation: 2961

Python warn prints message and call on Windows cmd

I'm having a problem with the display of warning messages in Python 2.7. Here's a minimum working example:

from warnings import warn

# It is a warning after all...
warn("Goodbye cruel world")

If I run this from the Windows command prompt, then I get the warning message but also the source code, e.g.

test.py:3: UserWarning: Goodbye cruel world
  warn("Goodbye cruel world")

What's going on here? How can I get it to only display the first line of this output?

Upvotes: 1

Views: 808

Answers (1)

falsetru
falsetru

Reputation: 369274

If you're trying to log something, logging module is more appropriate:

import logging

# logging.basicConfig(format='%(message)s')
logging.warn("Goodbye cruel world")

Upvotes: 1

Related Questions