import os

Chris Angelico rosuav at gmail.com
Sun Nov 16 20:34:50 EST 2014


On Mon, Nov 17, 2014 at 12:10 PM, Abdul Abdul <abdul.sw84 at gmail.com> wrote:
> Thanks for your reply. Yes, I came across this page, but didn't understand
> what is meant by the operating system dependent functionality. What does
> that mean? Is importing that module that serious?

It's not "serious" as in "using this module can break your code". What
it means is that stuff in the os module might not always be available;
on my Linux box, len(dir(os)) is 326, but on my Windows, it's only
145. (Similar Python versions.) A lot of the os module is available on
every platform you're ever likely to use, but need to be named
differently: for instance, os.curdir is the string representing the
current directory, and os.pathsep is the character that divides
entries in the PATH environment variable. You can assume that there
*will be* some kind of path separator, but you can't know whether
it'll be a semicolon (Windows), a colon (Unix), or something else, so
you call up the os module to find out. In fact, proper use of the os
module can make your code more, not less, cross-platform.

ChrisA



More information about the Python-list mailing list