-2

I want to make a counter from 0 to 2.097152 sec with 1 µsec step.

I tried with time.sleep() but this is not the right solution

I use Python 3.x

Thank you for your help

22buzz22
  • 23
  • 3
  • I don't understand what it is you're trying to do. A counter... of time... with 1 µsec steps... Do you want to do some task at 1 µsec intervals, or just do a sleep with 1 µsec granularity? – Craig McQueen Jan 16 '13 at 21:50
  • Woah. I agree that this question needs some clarification. But to downvote and close _before_ discussing seems harsh to me. It also seems to be against the friendly and constructive atmosphere that we want to have on this site. Cite from the FAQ "Above all, be honest. If you see misinformation, vote it down. **Add comments indicating what, specifically, is wrong. Provide better answers of your own. Best of all — edit and improve the existing questions and answers!**" – cfi Jan 17 '13 at 08:54
  • @22buzz22: Try to explain what you have done and why it would not work. `time.sleep()` is fairly accurate, and according to the docs even more accurate than the corresponding unix' sleep function. However, there's bound to be some inaccuracy. See [the manual](http://docs.python.org/3.2/library/time.html#time.sleep). [You'll be able to get to about 10-13ms](http://stackoverflow.com/questions/1133857/how-accurate-is-pythons-time-sleep). So what you want to do is likely not achievable. Maybe elaborate on the more general problem you're trying to solve and someone may be able to help you. – cfi Jan 17 '13 at 09:02

1 Answers1

0

You could have just searched for [python] range float

but anyways:

def msrange(start, stop, step=0.000001):
    while start <= stop:
        yield round(start, 6)
        if start + step > stop:
            yield stop
        start += step

then you can:

for i in msrange(0, 0.00003):
    print(i)

output:

0
1e-06
2e-06
3e-06
...
3e-05
mflatischler
  • 318
  • 1
  • 9