How to convert a stat output to a unix permissions string

python

Solution

Since Python 3.3 you could use `stat.filemode`:

In [7]: import os, stat

In [8]: print(stat.filemode(os.stat('/home/soon/foo').st_mode))
-rw-r--r--

In [9]: ls -l ~/foo
-rw-r--r-- 1 soon users 0 Jul 23 18:15 /home/soon/foo

Problem

If you run `os.stat(path)` on a file and then take its `st_mode` parameter, how do you get from there to a string like this: `rw-r--r--` as known from the Unix world?

Original source