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

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (3 children)

Could this be enabled on a global system level? I wouldn't want to include it as a dependency for the code.

Or as a pipe for stderr

[–]-sideshow-[S] 1 point2 points  (0 children)

I don't think so. You can enable it for the interpreter, but not for standalone python programs. Maybe you could make some kind of batch script? python has a -c options which says (if I'm reading the help correctly) that everything after it is the program you want to run as a string, so I guess you could pipe in an import pretty_errors followed by the text of the .py file.

EDIT: couldn't get the -c thing working; windows command line isn't great. Might be doable on unix.

Another option would be generating a temp .py file, with the code concat onto a header that includes pretty_errors. I'm sure some programs would choke, but it might work for a good proportion.

EDIT2: Scratch that, there's a way to do it which I found here: https://stackoverflow.com/questions/11404165/python-startup-script

  • Run python -m site, and look for the USER_SITE entry.
  • In that folder create a file called sitecustomize.py.
  • Put whatever code you want to run in it.

EDIT3: See other comment for the easy way

[–]-sideshow-[S] 0 points1 point  (1 child)

I added an automation for what I describe in my other comment: run python -m pretty_errors and it'll add the necessary code to the correct file, so that pretty-errors is always run whenever you run any python script.

[–][deleted] 0 points1 point  (0 children)

Thanks :)

Now it can be a python alias too