I'm on a Mac and I'd like to be able to sleep my computer from a python script. I can do it in bash with this command:
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
I read the instructions on this post and followed the instructions, but I ran into the following error.
import subprocess
subprocess.Popen("/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend")
FileNotFoundError: [Errno 2] No such file or directory: '/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend': '/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend'