Whenever I run a python script, a new line is also printed at the end.
The only way I can stop this is by using posix._exit(0) at the end to avoid Python’s cleanup code. Is there a more portable way?
(Sorry if this is a repeat question/seemingly obvious to answer. Unfortunately, I’ve only seen questions about printing without a newline)
Example script:
import os
#nothing actually done
Non-portable solution:
import os,posix
#nothing actually done
posix._exit()
OS: Windows
Tested with: Python in cygwin, native PyPy
What you describe is not normal python behavior, so something is probably odd about your setup. Try to debug it by stripping down what python does: Call python with
-E(ignore environment options) and/or-S(don’t loadsite). If that doesn’t help, look at the other python invocation options for ideas, or try using a debugger.Since
posix._exit(0), it’s likely that something (insite?) is setting an exit handler that generates the newline. Look upsys.exitfuncand the moduleatexit, and check whether they’re in use.