◐ Shell
clean mode source ↗

gh-102895 Add an option local_exit in code.interact to block exit() from terminating the whole process by gaogaotiantian · Pull Request #102896 · python/cpython

I'm okay with the if/else block instead of an inline statement, but I kind of changed the OS check on purpose.

The fundamental thing we want to know here is what's the EOF on a specific system, and the best effort we can make is to get the OS type - if it's Windows then it's Ctrl+Z + Return. os.sep is a design decision(finger print?) for Windows, the logic would be: os.sep == '\\' -> "this is Windows!". The seperator itself has nothing to do with what the eof directly, it just happens to be linked together because of Windows.

For similar checks, there are a lot of usage of sys.platform == "win32" in the standard library, and almost only site.py uses os.sep to figure out the OS platform. So I think sys.platform is actually preferred in this case.