all Python 3Linux · macOSosfunction
os.getgroups
os — user/group IDs
Return the list of supplemental group ids. Availability: Unix.
Syntax
os.getgroups(...)
It returns the current process's supplementary groups; the primary group may be absent from the list. On macOS the list may be incomplete or version-dependent, as the documentation warns. Groups assigned to the user after login show up only in a new session.
Examples
import os
print(os.getgroups()) # → ? только Unix: список GID групп процесса, например [4, 24, 27, 1000]
print(type(os.getgroups())) # → ? только Unix: <class 'list'>
print(27 in os.getgroups()) # → ? только Unix: True, если процесс входит в группу с GID 27 (sudo в Ubuntu)
print(len(os.getgroups())) # → ? только Unix: число групп; на macOS список обрезан (не более 16) и может расходиться с os.getgrouplist()
See also
Open in the full glossarydocs.python.orgReport an inaccuracy