Implementing some of 'ls -l" directly in python

Tim Daneliuk tundra at tundraware.com
Tue Nov 19 18:50:07 EST 2002


I have been looking high and low for several hours to answer a (probably
simple) question with no luck. So, to the PyGeniuses I go:

I want to implement something similar to an 'ls -l file' in a script I'm
writing. I'd like to avoid actually spawning 'ls' because I want to
script to run on Win32 as well as *nix.

So, I use os.path.getmtime and os.path.getsize for two of the things I
need. I then stat the file to get its UID, GID, and permission bits.
Here's where I get stuck. I cannot seem to find a portable way to
convert the UID/GID into their equivalent string names. Also, it would
be handy if there were a (portable) way to convert the permission value
into the more familiar u/g/o - drwx format.

Ideas?

-- 
------------------------------------------------------------------------------
Tim Daneliuk
tundra at tundraware.com




More information about the Python-list mailing list