if you want POSIX, import posix, not os
Dan Connolly
connolly at w3.org
Tue Aug 17 00:58:43 EDT 1999
I have thought this was broken for years, but I just read
it again tonight, and I'm not going to pass over it in silence this
time:
"Do not import this module directly. Instead, import the module os,
which provides a portable version of this interface."
-- http://www.python.org/doc/1.5.2p1/lib/module-posix.html
I think this is terrible advice.
The os module is *not* portable:
"getpgrp ()
Return the current process group id. Availability: Unix. "
-- http://www.python.org/doc/1.5.2p1/lib/os-procinfo.html
on my NT box:
>>> import os
>>> os.getpgrp()
Traceback (innermost last):
File "<interactive input>", line 0, in ?
AttributeError: getpgrp
What's portable about that?
A portable interface is one where I can expect consistent behaviour
of named objects across platforms, no?
All I know about a python program that imports os is that
it might work on some platforms and not on others. That's
the exact *opposite* of portable, no?
The IEEE POSIX spec is widely implemented and understood.
When a program expects behaviour as specified in the POSIX
specs, it should say
import posix
no? If an implementation on WinNT provides posix semantics,
then it may supply a module by that name that works as
expected. Otherwise, I want an early ImportError, not
later AttributeErrors, or worse: silent failures to
behave as specified.
It would have made sense for python to define a really portable os
module, i.e. the least common denominator of the platforms it
runs on. But that's not what we've got.
I hope the os module will be deprecated in future releases.
--
Dan Connolly, W3C
http://www.w3.org/People/Connolly/
More information about the Python-list
mailing list