Python Glossary Русский

Python 3.3+Linuxosfunction

os.listxattr

os — extended attributes (xattr)

Return the list of a file's extended attribute names.

Syntax

os.listxattr(...)

It returns attribute names with their prefixes, e.g. ['user.comment', 'security.selinux']. Some attributes are created by the system itself — SELinux, ACLs — so even a "clean" file may have a non-empty list. Read values separately with getxattr.

Examples

import os
open('xattr_demo.txt', 'w').close()
os.setxattr('xattr_demo.txt', 'user.author', b'anna')   # → ? только Linux: записали расширенный атрибут (имя обязано начинаться с user.)
print(os.listxattr('xattr_demo.txt'))   # → ['user.author']
print(os.listxattr())   # → ? только Linux: без аргумента смотрит текущий каталог, обычно []
print(os.listxattr('нет-такого'))   # → FileNotFoundError

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy