Ok nevermind, I did not figure it out. My code... count = 0 while count < 3: count += 1 Subprocess.Popen('command') if count == 3: sys.exit()
This does not work as I want it to; it consecutively executes the command three times in a row. I only want it to execute once. However, if there is an error, I want it to try again, but only if count does not equal 3. If count equals 3, i want it to give up and exit or do something else. Bo > On Sep 5, 2014, at 4:40 PM, tutor-requ...@python.org wrote: > > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-requ...@python.org > > You can reach the person managing the list at > tutor-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > > Today's Topics: > > 1. Re: How to count vehicle? I'm trying but my code don't > increasing.. (Whees Northbee) > 2. Re: How to count vehicle? I'm trying but my code don't > increasing.. (Steven D'Aprano) > 3. Re: How to count vehicle? I'm trying but my code don't > increasing.. (Marc Tompkins) > 4. How to detect colinearity? (Danny Yoo) > 5. command counter (Bo Morris) > 6. command counter (Bo Morris) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Fri, 5 Sep 2014 18:09:45 +0700 > From: Whees Northbee <ch.de2.2...@gmail.com> > To: Danny Yoo <d...@hashcollision.org> > Cc: "tutor@python.org" <tutor@python.org> > Subject: Re: [Tutor] How to count vehicle? I'm trying but my code > don't increasing.. > Message-ID: > <CAGPegViH=pGbcQ-n1Wukwy0e1b=S=twje=l01ccgmja0yr6...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > I'm really sorry if my post doesn't appropriate to the forum rule.. I > already asked in other forums 2 months ago, but no answer or had voted down > and closed.. If you ask me about the basic slope formula or basic theory of > intersection of point with a line I know, that's why I try with "if" code > since the line is have the same y coordinate there's no slope, so I think > if the y coordinate point same with y coordinate line no matter the value > of x coordinate as long as the y coordinate same, the counter increasing.. > but if you're think I'm expert with python because I'm work with computer > vision I'm not I'm newbie to both.. I'm sorry.. > > > On Wed, Sep 3, 2014 at 6:04 AM, Danny Yoo <d...@hashcollision.org> wrote: > >>> >>> On Tue, Sep 2, 2014 at 7:01 AM, Whees Northbee <ch.de2.2...@gmail.com> >> wrote: >>>> If all of these confusing, I'll simplify the problem, I need to know if >> a >>>> point (x,y) exactly at a line where line is (ax1,ay) to (ax2,ay).. >>> >>> >>> Case in point: in the question above, you can't possibly be asking us >>> to help you write a predicate that tells whether a point is on a line. >>> So I have to be misunderstanding your question. You must be asking >>> for a library function in OpenCV, and I'm pretty sure none of us are >>> OpenCV experts. >> >> >> Ok, found an OpenCV-specific answer about this: >> >> >> http://stackoverflow.com/questions/5596805/opencv-detect-if-points-lie-along-line-plane >> >> As expected, this is very domain-specific, and probably not suitable >> for Python-tutor. > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > <http://mail.python.org/pipermail/tutor/attachments/20140905/3114460a/attachment-0001.html> > > ------------------------------ > > Message: 2 > Date: Sat, 6 Sep 2014 03:40:43 +1000 > From: Steven D'Aprano <st...@pearwood.info> > To: tutor@python.org > Subject: Re: [Tutor] How to count vehicle? I'm trying but my code > don't increasing.. > Message-ID: <20140905174043.gq9...@ando.pearwood.info> > Content-Type: text/plain; charset=us-ascii > >> On Fri, Sep 05, 2014 at 06:09:45PM +0700, Whees Northbee wrote: >> I'm really sorry if my post doesn't appropriate to the forum rule.. I >> already asked in other forums 2 months ago, but no answer or had voted down >> and closed.. > > It's not a matter about breaking some rule, but about you getting an > answer. Your question is very narrowly specific to a particular software > library. Of all the people here, YOU probably know more about it than > all the rest of us together. > > Even though OpenCV *uses* Python, your question is not about Python. It > is about computer vision, and we know less than you about computer > vision. > > > > -- > Steven > > > ------------------------------ > > Message: 3 > Date: Fri, 5 Sep 2014 10:41:03 -0700 > From: Marc Tompkins <marc.tompk...@gmail.com> > To: Whees Northbee <ch.de2.2...@gmail.com> > Cc: "tutor@python.org" <tutor@python.org> > Subject: Re: [Tutor] How to count vehicle? I'm trying but my code > don't increasing.. > Message-ID: > <cakk8jxbotmu6hytrupimw2mr4j0uo+v+wkzuel2ttr3pu6d...@mail.gmail.com> > Content-Type: text/plain; charset=UTF-8 > >> On Fri, Sep 5, 2014 at 4:09 AM, Whees Northbee <ch.de2.2...@gmail.com> wrote: >> I'm really sorry if my post doesn't appropriate to the forum rule.. I >> already asked in other forums 2 months ago, but no answer or had voted down >> and closed.. > > It's not that you've broken a rule. It's just that you're asking on a > forum where you're not likely to get an answer, because nobody here > (that I am aware of) is an expert in computer vision. The way you > phrased the question at first made it sound like you were asking about > the basic math - we can help you with that, and with turning that math > into Python. But for questions about OpenCV, you're going to have to > ask in a place where people actually use OpenCV. It's not a matter of > etiquette or forum rules - it's a matter of asking in a place where > people can actually answer your question. If you asked in OpenCV > forums, and got no answer/voted down... we're sorry, but we can't > really help you with that. > > > ------------------------------ > > Message: 4 > Date: Fri, 5 Sep 2014 12:35:17 -0700 > From: Danny Yoo <d...@hashcollision.org> > To: Whees Northbee <ch.de2.2...@gmail.com> > Cc: "tutor@python.org" <tutor@python.org> > Subject: [Tutor] How to detect colinearity? > Message-ID: > <cagzapf5fy27najmflbn_n6km0j4lfpn1qzigpwczofgkzgh...@mail.gmail.com> > Content-Type: text/plain; charset=UTF-8 > >> But if you're think I'm expert with python because I'm work with computer >> vision >> I'm not I'm newbie to both.. > > Ok. Since you've stated that you are a beginner, we now have to > recalibrate how we're answering your questions. > > In that case, I would strongly suggest going through a basic > programming tutorial first, before tackling anything with computer > vision. Otherwise, you'll keep getting tripped up on issues that > people will assume you already know about. > > There are several tutorials you can take a look at: > > https://wiki.python.org/moin/BeginnersGuide/NonProgrammers > > Personally, I like: > > http://openbookproject.net/thinkcs/python/english2e/ > > but the other tutorials from the link above should be fine. > > > >> If you ask me about the basic slope formula or basic theory of >> intersection of point with a line I know, that's why I try with "if" code >> since the line is have the same y coordinate there's no slope, so I think if >> the y coordinate point same with y coordinate line no matter the value of x >> coordinate as long as the y coordinate same, the counter increasing. > > So you've tried to use the idea of slope, but have discovered that > when the line is vertical, using a slope approach does not work on > such lines. Yes. That's one of the problems with using the slope > approach. > > There are more general approaches that avoid the whole slope problem, such as: > > http://stackoverflow.com/questions/328107/how-can-you-determine-a-point-is-between-two-other-points-on-a-line-segment > > which talks about an alternative approach. The proposed function they > use there is: > > ############################################################# > def isBetween(a, b, c): > crossproduct = (c.y - a.y) * (b.x - a.x) - (c.x - a.x) * (b.y - a.y) > if abs(crossproduct) > epsilon : return False > > dotproduct = (c.x - a.x) * (b.x - a.x) + (c.y - a.y) * (b.y - a.y) > if dotproduct < 0 : return False > > squaredlengthba = (b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y) > if dotproduct > squaredlengthba: return False > > return True > ############################################################# > > where a, b, and c are objects with x and y components. It's more > general because it doesn't use division: rather, they use cross > products and dot products. Vector arithmetic to the rescue, > basically. > > > But note the "epsilon" free variable there: that's an indication that > we have to be careful about floating point arithmetic. > > I used the term "floating point arithmetic" earlier in one of my first > replies because I hoped that would trigger concepts that I had assumed > that you had learned about already. > > I saw that you were using exact equality on numbers, and for folks who > have done some beginner-style computer arithmetic, the term "floating > point arithmetic" should be a big warning sign to be careful about > equality. > > But now that you've said more of your background, I can't assume you > know what "floating point" arithmetic means. > > Please read: > > https://docs.python.org/2/tutorial/floatingpoint.html > > for a brief introduction. > > After reading that, you should have a better understanding as to why > your programs not use exact equality when floating point numbers are > concerned. > > > ------------------------------ > > Message: 5 > Date: Fri, 5 Sep 2014 16:32:17 -0400 > From: Bo Morris <crushe...@gmail.com> > To: "tutor@python.org" <tutor@python.org> > Subject: [Tutor] command counter > Message-ID: > <CAKKCnfdz1x=RuU9pKR=hrpruhags6f5w97ge33sywp3r59z...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > 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 > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > <http://mail.python.org/pipermail/tutor/attachments/20140905/77fea49d/attachment-0001.html> > > ------------------------------ > > Message: 6 > Date: Fri, 5 Sep 2014 16:40:08 -0400 > From: Bo Morris <crushe...@gmail.com> > To: "tutor@python.org" <tutor@python.org> > Subject: [Tutor] command counter > Message-ID: > <cakkcnfdu0w4mdlrmt5sbhyztuxf01bhgtq5yu5n-ejlarnl...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > 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 > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > <http://mail.python.org/pipermail/tutor/attachments/20140905/95d79c0d/attachment.html> > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Tutor maillist - Tutor@python.org > https://mail.python.org/mailman/listinfo/tutor > > > ------------------------------ > > End of Tutor Digest, Vol 127, Issue 15 > ************************************** _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor