Search code examples
pythonglibc

How to use libc's listxattr in python code?


I'm a python newbie, I want to parse all the extended attributes of a file and perform some operation if it matches a particular pattern. For Ex. I have to search for attributes of the pattern user.thing* like user.thing1 user.thing2 etc. and I have to perform some operations based on the matching. In C I can do a listxattr and if the a particular key has the pattern I wish for I can do a getxattr on the same. How to accomplish the same in python.


Solution

  • You use the xattr package.

    $ easy_install xattr
    $ python
    >>> import xattr
    >>> dict(xattr.xattr('.'))
    {}