sys.platform documentation?

M

Michiel Sikma

Hello everybody,

I was thinking about making a really insignificant addition to an
online system that I'm making using Python: namely, I would like it
to print the platform that it is running on in a human-readable
manner. I was thinking of doing it like this:

import sys

platforms = {
'darwin': 'Darwin',
'win32': 'Microsoft Windows',
'freebsd6': 'FreeBSD 6.0'
}

def version():
return '%s, running on %s.' % (NAME, platforms[sys.platform])

However, in order to populate the list of platforms, I need to know
which strings sys.platform can return. I haven't found any
documentation on this, but I guess that I'm not looking in the right
places! Do any of you know where I can find a list of possible return
values from sys.platform? I'll settle for a Python C source code
file, too, if it contains strings.

Regards,

Michiel
 
S

Sybren Stuvel

Michiel Sikma enlightened us with:
However, in order to populate the list of platforms, I need to know
which strings sys.platform can return. I haven't found any
documentation on this, but I guess that I'm not looking in the
right places! Do any of you know where I can find a list of
possible return values from sys.platform? I'll settle for a Python
C source code file, too, if it contains strings.

I've browsed through the Python source, and I can't find this list. My
best guess is that it's set by ./configure at compile-time, most
likely using the output of 'uname' as source of information.

Sybren
 
M

Michiel Sikma

Op 10-aug-2006, om 10:44 heeft Sybren Stuvel het volgende geschreven:
Michiel Sikma enlightened us with:

I've browsed through the Python source, and I can't find this list. My
best guess is that it's set by ./configure at compile-time, most
likely using the output of 'uname' as source of information.

Sybren

So there probably isn't even any kind of list that we can find?
That's too bad. It's not a big loss to me, but I imagine that it's
kind of annoying if you really need to add OS-specific code. Maybe we
need to request that documentation for it is implemented in the
official Python documentation once and for all. I guess that would
require e-mailing a lot of people (like via this list) and asking
them which operating system they're on and what their sys.platform
tells them?

Michiel
 
S

Sybren Stuvel

Michiel Sikma enlightened us with:
So there probably isn't even any kind of list that we can find?
That's too bad. It's not a big loss to me, but I imagine that it's
kind of annoying if you really need to add OS-specific code. Maybe
we need to request that documentation for it is implemented in the
official Python documentation once and for all. I guess that would
require e-mailing a lot of people (like via this list) and asking
them which operating system they're on and what their sys.platform
tells them?

There is a limited (as in not infinite) number of platforms Python
runs on, so it should be possible to get a list of all sys.platform
names.

Another method would be to send you an email if the value of
sys.platform doesn't exist in the dict yet. Then you can add it in
newer versions. That also ensures the up-to-date-ness of the list.

Sybren
 
M

Michiel Sikma

Op 10-aug-2006, om 11:50 heeft Sybren Stüvel het volgende geschreven:
There is a limited (as in not infinite) number of platforms Python
runs on, so it should be possible to get a list of all sys.platform
names.

I guess that I could try and assemble some values and then submit
them to the Python documentation.

So here's the question of the day: what does your sys.platform tell
you? :)

I'm on Mac OS X 10.4 and my sys.platform says 'darwin'.
Another method would be to send you an email if the value of
sys.platform doesn't exist in the dict yet. Then you can add it in
newer versions. That also ensures the up-to-date-ness of the list.

I'll definitely do that as well. I'm also sure that OS-specific code
can also be found in online source code, so I'll see if I can find
some there as well.

Greets,
Michiel
 
S

Sybren Stuvel

Michiel Sikma enlightened us with:
So here's the question of the day: what does your sys.platform tell
you? :)

Ubuntu Linux 6.06 Dapper Duck kernel 2.6.15-26-686, it says 'linux2'.

Sybren
 
R

Rob Wolfe

Michiel said:
So here's the question of the day: what does your sys.platform tell
you? :)


uname -srv
HP-UX B.11.00 D

python -c "import sys; print sys.platform"
hp-ux11


Regards,
Rob
 
T

Tim Golden

Michiel said:
Hello everybody,

I was thinking about making a really insignificant addition to an
online system that I'm making using Python: namely, I would like it
to print the platform that it is running on in a human-readable
manner. I was thinking of doing it like this:

[... snip ...]
However, in order to populate the list of platforms, I need to know
which strings sys.platform can return. I haven't found any
documentation on this

Not that this answers your question directly, but is the
platform module of any more use to you?

http://docs.python.org/lib/module-platform.html

TJG
 
M

Michiel Sikma

Op 10-aug-2006, om 13:00 heeft Tim Golden het volgende geschreven:
Michiel said:
Hello everybody,

I was thinking about making a really insignificant addition to an
online system that I'm making using Python: namely, I would like it
to print the platform that it is running on in a human-readable
manner. I was thinking of doing it like this:

[... snip ...]
However, in order to populate the list of platforms, I need to know
which strings sys.platform can return. I haven't found any
documentation on this

Not that this answers your question directly, but is the
platform module of any more use to you?

http://docs.python.org/lib/module-platform.html

TJG

--
http://mail.python.org/mailman/listinfo/python-list

I didn't even know there was a platform module. Too bad that one also
does not have documentation on possible values for common systems.

It seems that uname() is the most resourceful function. So if I do this:
('Darwin', 'imac-g5-van-michiel-sikma.local', '8.6.0', 'Darwin Kernel
Version 8.6.0: Tue Mar 7 16:58:48 PST 2006; root:xnu-792.6.70.obj~1/
RELEASE_PPC', 'Power Macintosh', 'powerpc')

That's on Mac OS X 10.4.6. Indeed more useful.

Michiel
 
S

Simon Forman

Michiel said:
Op 10-aug-2006, om 13:00 heeft Tim Golden het volgende geschreven:
Michiel said:
Hello everybody,

I was thinking about making a really insignificant addition to an
online system that I'm making using Python: namely, I would like it
to print the platform that it is running on in a human-readable
manner. I was thinking of doing it like this:

[... snip ...]
However, in order to populate the list of platforms, I need to know
which strings sys.platform can return. I haven't found any
documentation on this

Not that this answers your question directly, but is the
platform module of any more use to you?

http://docs.python.org/lib/module-platform.html

TJG

I didn't even know there was a platform module. Too bad that one also
does not have documentation on possible values for common systems.

It seems that uname() is the most resourceful function. So if I do this:
('Darwin', 'imac-g5-van-michiel-sikma.local', '8.6.0', 'Darwin Kernel
Version 8.6.0: Tue Mar 7 16:58:48 PST 2006; root:xnu-792.6.70.obj~1/
RELEASE_PPC', 'Power Macintosh', 'powerpc')

That's on Mac OS X 10.4.6. Indeed more useful.

Michiel

It might be a good idea to write a brief script to print out
sys.platform, platform.platform(), platform.uname(), etc.. and post it
here for people to run and post their results.

Peace,
~Simon
 
M

Michiel Sikma

Op 10-aug-2006, om 19:18 heeft Simon Forman het volgende geschreven:
It might be a good idea to write a brief script to print out
sys.platform, platform.platform(), platform.uname(), etc.. and
post it
here for people to run and post their results.

Peace,
~Simon

sys.platform is actually not needed anymore once you use platform, it
seems.

So if you run this script:
--
import platform
platform.platform()
platform.uname()
--
You will get all the information that is necessary. And then you just
need to provide it with a human-determined name of the operating
system you're using.

My output:
('Darwin', 'imac-g5-van-michiel-sikma.local', '8.6.0', 'Darwin
Kernel Version 8.6.0: Tue Mar 7 16:58:48 PST 2006;
root:xnu-792.6.70.obj~1/RELEASE_PPC', 'Power Macintosh', 'powerpc')

And I'm on Mac OS X 10.4.6 on a G5 iMac.

Michiel
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Michiel said:
However, in order to populate the list of platforms, I need to know
which strings sys.platform can return. I haven't found any documentation
on this, but I guess that I'm not looking in the right places! Do any of
you know where I can find a list of possible return values from
sys.platform? I'll settle for a Python C source code file, too, if it
contains strings.

As others have indicated, sys.platform is derived from the name that
the system vendor gives their system. However, Python also adds
plat-<sys.platform> to sys.path, so you can look at all the plat-*
directories in the Python distribution.

This gives you the list

aix3 aix4 atheos beos5 darwin freebsd2 freebsd3 freebsd4 freebsd5
freebsd6 freebsd7 generic irix5 irix6 linux2 mac netbsd1 next3 os2emx
riscos sunos5 unixware7

Of course, sys.platform can have additional values, when Python
gets compiled on a system for which no platform-specific directory
has been created.

Regads,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top