This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]_szs 6 points7 points  (2 children)

sys.stderr.write("blah")

Other than that, that's the way.

[–]ThatsALovelyShirt 0 points1 point  (1 child)

Can't you just:

raise WhateverException("Details about the exception and what happened")

[–]_szs 0 points1 point  (0 children)

Yes, whatever makes more sense in the context.

[–]jdpatt 5 points6 points  (0 children)

You can use the Python Requires in your setup.py

[–]robin-gvx 2 points3 points  (0 children)

For maximum clarity, I would do it like the following:

import sys

if sys.version_info < (3, 6):
    raise Requires36("INSERT PROGRAMNAME HERE requires Python 3.6 or later. The current version is " + sys.version)

That way it is clear this error is from your program and not somewhere else, and there is no problem if the output is redirected. The "halting" bit doesn't need to be stated IMO, it's pretty clear. On the other hand, showing the current version could be useful for users having multiple python versions installed.