I need to write data to a file that requires administrative rights. And I need this script to work without sudo, because I need the current username, and when I run it with sudo, it is replaced with 'root', which does not suit me:
import getpass print(getpass.getuser()) # Output: 'root' при запуске скрипта с sudo So my problem will be solved by one of two things: either how to change 'root' to the current username, or how to write data to the file with administrator privileges, implementing it in Python.