How to check that my python script is running under Administrator rights (sudo) under BSD-like OS? Need to display user-friendly warning in order it is executed without admin rights.
Don't be tempted to match a username against the string "root".
Generally you will either have to provide less efficient callouts to obtain the textual representation of the UID or you will be relying on environment variables which may not be so trustworthy.
How about this? Check if
uid == 0
:How about that one:
Don't be tempted to match a username against the string "root".
Generally you will either have to provide less efficient callouts to obtain the textual representation of the UID or you will be relying on environment variables which may not be so trustworthy.