On 06/06/2013 08:03 PM, cerr wrote:
Hi,

I have a process that I can trigger only at a certain time. Assume I have a TDM 
period of 10min, that means, I can only fire my trigger at the 5th minute of 
every 10min cycle i.e. at XX:05, XX:15, XX:25... For hat I came up with 
following algorithm which oly leaves the waiting while loop if minute % TDM/2 
is 0 but not if minute % TDM is 0:
        min = datetime.datetime.now().timetuple().tm_hour*60 + 
datetime.datetime.now().timetuple().tm_min
        while not (min%tdm_timeslot != 0 ^ min%(int(tdm_timeslot/2)) != 0):

You might have spent three minutes and simplified this for us. And in the process discovered the problem.

(BTW, min() is a builtin function, so it's not really a good idea to be shadowing it.)

You didn't give python version, so my sample is assuming Python 2.7 For your code it shouldn't matter.

tdm = 10
tdm2 = 5

y = min(3,4)
print y

for now in range(10,32):
    print now, now%tdm, now%tdm2,
    print not(now % tdm !=0 ^ now%tdm2 !=0) #bad
    print not((now % tdm !=0) ^ (now%tdm2 !=0))  #good


Your problem is one of operator precedence. Notice that ^ has a higher precedence than != operator, so you need the parentheses I added in the following line.

What I don't understand is why you used this convoluted approach.  Why not

    print now%tdm != tdm2

For precedence rules, see:
  http://docs.python.org/2/reference/expressions.html#operator-precedence




--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to