[Tutor] command counter
Dave Angel
davea at davea.name
Sat Sep 6 04:46:12 CEST 2014
Crush <crushed26 at gmail.com> Wrote in message:
> My code is as follows...
>
> count = 0
> while count < 3:
> count += 1
> subprocess.Popen('command')
> if count == 3:
> sys.exit()
>
>
The line beginning "subp" is indented further than the one before
it, so this script would terminate with an indentation error.
Once you've fixed that we should look at the if statement. If the
count is 3 it calls sys.exit. But of course count is 3, or we
wouldn't have finished the while loop. And you terminate anyway
when you fall off the end of the script. So why call sys.exit
()
Finally, if you just want to something 3 times, why not use a for
loop?
for count in range (3):
subproc...
--
DaveA
More information about the Tutor
mailing list