Hi
I have been trying to do one of the projects in the projects for beginners section that asks you to get your computer to log off after a certain amount of time has passed without any mouse or keyboard movement. I am not yet up to that bit, in fact i can't work out how to log off/shut down. It says to use the os module but i cant find anything that will do the trick.

I was wondering if anybody could point me in the right direction? Thanks in advance :).

On windows, I was able to shutdown the system with

import os
os.system("shutdown -s")

On linux, it was

import os
os.system("sudo shutdown -h now")

Note that normaly on linux, only the superuser can shutdown the machine with 'shutdown'. Other users must be allowed to do so by the superuser. This page http://www.spencerstirling.com/computergeek/shutdown.html explains how.

I don't know the commands on osx, or other systems.
A portable program should choose the command depending on the underlying system, may be by examining the content of sys.platform :)

commented: Great Answer! +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.