Perl conversion to python...

Hans Mulder hansmu at xs4all.nl
Tue Nov 24 23:38:03 CET 2009


J Kenneth King wrote:
> Benjamin Schollnick <bschollnick at gmail.com> writes:

>> 		select(undef, undef, undef, 0.01);

>         # select() is a system call in Perl..
>         # insert Python equivalent here

That would be:

           time.sleep(0.01)

Perl has a sleep() built-in, but it truncates its argument to an int.
If you want to sleep less than a second in Perl, you have to use select
as shown.

Not so in Python.  Python's time.sleep() takes a float argument and
calls some platform-dependent function that provides sleeping with
sub-second accuracy.  On some platforms, it ends up calling the
C level select() function.

Keep in mind that in both languages, your program may end up sleeping
longer than it should due to scheduling or other activity on the system.


Hope this helps,

-- HansM




More information about the Python-list mailing list