Search code examples
pythonlinuxpython-idle

.py file from Linux to Windows: is it going to just work?


I am using Python 2.7.5+ on my Linux Mint to write simple programs as .py files and running them in Konsole Terminal. These work fine on my computer, but I need to share them with a friend using Windows (IDLE I suppose) and wonder if these will work as they are without modification.

The programs start with the usual #!/usr/bin/python, you know.


Solution

  • Most Python code will work fine, but the shebang (#!) does nothing on Windows - only the filename extension (.py or .pyw) does. If you're handling filenames you'll want to use the functions in os.path. Line endings also differ, which means you'll want to tell open() whether you're reading text or binary data. This also shows up in less adaptive text editors like Windows Notepad (and sadly in Idle when pasting). Notepad++ is one capable text editor for Windows. There are also some restrictions for multiprocessing in Windows.