I would like to redirect stderr
and stdout
to files when run inside of pythonw
. How can I determine whether a script is running in pythonw
or in python
?
Asked
Active
Viewed 1,427 times
2

Georg Schölly
- 124,188
- 49
- 220
- 267
1 Answers
5
sys.executable
-- "A string giving the name of the executable binary for the Python interpreter, on systems where this makes sense."

Steve Gilham
- 11,237
- 3
- 31
- 37
-
On my mac it says `/System/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python` (which does make perfect sense) whether I run python or pythonw. – Alex Martelli Oct 23 '09 at 05:44
-
3The Mac doesn't need Pythonw anymore (since 2.3). Pythonw is only interesting for windows developers anymore. – Georg Schölly Oct 23 '09 at 05:50
-
I don't think that is true about Macs. I have some issues that are only resolved by using pythonw. – Christopher Barber Jan 21 '21 at 21:57
-
This does not work on Mac becasue pythonw sets the environment variable PYTHONEXECUTABLE to point to the regular python script. – Christopher Barber Jan 21 '21 at 22:05