w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Defining the command line arguments of a linux command in python

format is your friend:

import os, sys 
if len(sys.argv) == 2:
  os.system("sudo rtcwake -m off -s {}".format(sys.argv[1]))
else: print "usage: ..."

so the seconds are command line parameters. Or, you can make it interactive:

import os
secs = raw_input()
os.system("sudo rtcwake off -s {}".format(secs))

to verify that the user input is an integer:

try:    secs = int(secs)
except: print 'usage: '

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.