| Store | Cart

Re: Using python to start programs after logging in

From: MRAB <pyt...@mrabarnett.plus.com>
Thu, 19 Jan 2017 20:12:30 +0000
On 2017-01-19 19:08, Cecil Westerhof wrote:
> I am writing a python program to start the programs that need to be> started after logging in.>> I have the following imports:>     from subprocess import check_call, Popen, STDOUT>     from time       import sleep, strftime>> And use the following code:>     check_call(tuple('wmctrl -s 10'.split()))>     log_file = open('Logging/firefox_%T.log'.replace('%T', strftime('%F_%R')), 'w')>     Popen(tuple('firefox'.split()), stdout = log_file, stderr = STDOUT)>> The first statement is to go to the correct desktop.>> Is this a good way to do things, or could I do it in a better way?>
Apart from the other answer, your use of .replace is odd. This would be 
better:

     log_file = open('Logging/firefox_%s.log' % strftime('%F_%R'), 'w')

Even better would be to use the 'with' statement as well.

-- 
https://mail.python.org/mailman/listinfo/python-list

Recent Messages in this Thread
Cecil Westerhof Jan 19, 2017 07:08 pm
John Gordon Jan 19, 2017 07:29 pm
Cecil Westerhof Jan 19, 2017 09:11 pm
John Gordon Jan 20, 2017 05:46 pm
MRAB Jan 19, 2017 08:12 pm
Cecil Westerhof Jan 19, 2017 09:21 pm
Cecil Westerhof Jan 19, 2017 11:36 pm
MRAB Jan 20, 2017 12:24 am
Cecil Westerhof Jan 20, 2017 04:26 am
Cecil Westerhof Jan 20, 2017 04:34 am
Cecil Westerhof Jan 23, 2017 11:53 am
Messages in this thread