Re: [Tutor] command counter
Crush 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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] command counter
Here is the shell script I am trying to recreate in python. Sorry for not posting this with my other emails...I am a bit off today. restart_count=10 count=10 restart=5 while ((count--)); do avconv -v verbose -re -analyzeduration 0 | ./bmdplay -m 2 -f pipe:0 echo "Retry" if [[ $count = 1 ]] && [[ $restart != 1 ]]; then sleep 10 ((restart--)) count=$restart_count fi done echo "Gave up" ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] command counter
My code is as follows... count = 0 while count < 3: count += 1 subprocess.Popen('command') if count == 3: sys.exit() 'command' is any command. For testing, I have been using the command 'xterm' just so I can see it opening. As far as error and pertaining to the above code, if I close the xterm window, have it open back up until the counter reaches the specified number. I am basically trying to recreate in python a shell script I use. The current shell script runs a real long avconv/ bmdplay command and if the command stops running, the script will try and rerun it until count equals n number. Again, I am only using xterm temporarily while I try to get the logic correct. Once correct, I can change the command and still have the same outcome...I think. I am not using a function. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] command counter
Bo Morris Wrote in message: > > subprocess.Popen("command") && add 1 to count. If count equals n number, do something. > I have tried count = 0 count += 1, but count does not seem to be > incrementing. It would be much better to post the code that "does not seem..." There are many possible reasons that count might not seem to change. For example, are you incrementing inside a function and checking it elsewhere? If so, look up the keyword global, or make count part of the return value. Please show your code. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] command counter
I think I figured it out... each time I run subprocess.Popen("command"), I also have to count += 1, which adds 1 to count each time the command is run. Is this correct, or is there a better way? Thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] command counter
how would I keep track of count for each time a command exectuted? for example... subprocess.Popen("command") && add 1 to count. If count equals n number, do something. I have tried count = 0 count += 1, but count does not seem to be incrementing. Thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor