views:

227

answers:

4

I am about to start a personal project using python and I will be using it on both Linux(Fedora) and Windows(Vista), Although I might as well make it work on a mac while im at it. I have found an API for the GUI that will work on all 3. The reason I am asking is because I have always heard of small differences that are easily avoided if you know about them before starting. Does anyone have any tips or suggestions that fall along these lines?

+4  A: 

In general:

  • Be careful with paths. Use os.path wherever possible.
  • Don't assume that HOME points to the user's home/profile directory.
  • Avoid using things like unix-domain sockets, fifos, and other POSIX-specific stuff.

More specific stuff:

  • If you're using wxPython, note that there may be differences in things like which thread certain events are generated in. Don't assume that events are generated in a specific thread. If you're calling a method which triggers a GUI-event, don't assume that event-handlers have completed by the time your method returns. (And vice versa, of course.)
  • There are always differences in how a GUI will appear. Layouts are not always implemented in the exact same way.
JesperE
+1  A: 
  1. You should take care of the Python version you are developing against. Especially, on a Mac, the default version of Python installed with the OS, is rather old (of course, newer versions can be installed)

  2. Don't use the OS specific libraries

  3. Take special care of 'special' UI elements, like taskbar icons (windows), ...

  4. Use forward slashes when using paths, avoid C:/, /home/..., ... Use os.path to work with paths.

KornP
don't use forward slashes - use os.sep instead, not everything on windows works properly with forward slashes
Moe
I prefer using os.normpath() since it will normalize to whatever os.sep is, among other things.
Soviut
Agreed, my point was mainly to not use forward slashes.
Moe
Even better is to avoid slashes altogether and use os.path.join
dF
+3  A: 

Some things I've noticed in my cross platform development in Python:

  • OSX doesn't have a tray, so application notifications usually happen right in the dock. So if you're building a background notification service you may need a small amount of platform-specific code.
  • os.startfile() apparently only works on Windows. Either that or Python 2.5.1 on Leopard doesn't support it.
  • os.normpath() is something you might want to consider using too, just to keep your paths and volumes using the correct slash notation and volume names.
  • icons are dealt with in fundamentally different ways in Windows and OSX, be sure you provide icons at all the right sizes for both (16x16, 24x24, 32x32, 48x48, 64x64, 128x128 and 256x256) and be sure to read up on setting up icons with wx widgets.
Soviut
A: 

Some filename problems: This.File and this.file are different files on Linux, but point to the same file on Windows. Troublesome if you manage some file repository and access it from both platforms. Less frequent related problem is that of names like NUL or LPT being files on Windows.

Binary distribution code (if any) would likely use py2exe on Win, py2app on Mac and wouldn't be present on Linux.

Mekk
pyInstaller can be used to create Windows and Linux compatible exe's while py2app works for mac.
Soviut