Q:

how to "conditionally compile" python

Yes, I know, but it was the only way to summarize what I want to do.
For opening a serial port I want to use:
    portfd = os.open(portname, os.O_RDWR | os.O_NONBLOCK)

Problem is that O_NONBLOCK doesn't exist under windows, which means it blows up here. I'm testing under windows for deployment under an OS that supports non block.
So what I really want is for the O_NONBLOCK to go away or have it #defined for the windows environment with 0 so that I can go about my business without having an error.
Any ideas?
PS: Please don't explain about how python compiles/interprets. I get it, but I'm trying to communicate an idea.

A:

Another method nobody has yet suggested:
portfd = os.open(portname, os.O_RDWR | getattr(os, 'O_NONBLOCK', 0))

This is the easy way to default any attribute that might not exist.

