restart local computer from python
问题 Is there any way to make the computer a Python program is running on restart? Generic solution is good, but in particular I'm on windows. 回答1: There is no generic way of doing this, afaik. For Windows, you need to access the Win32 API. Like so: import win32api win32api.InitiateSystemShutdown() The win32api module is a part of pywin32. For linux/os x, I guess calling the "reboot" command is the easiest. import os os.system('reboot now') Or something like that. (Note to downvoters: os.system()