CodeSkulptor time delay: no attribute 'sleep'

557 Views Asked by At

In CodeSkulptor (online Python coding page) I wrote a simple code, with a time delay. So simple:

import time
time.sleep(5)
print("random string")

When I press run, I got an error message: Line 2: AttributeError: '<invalid type>' object has no attribute 'sleep'

Any ideas what is wrong? Or how can I fix it?

2

There are 2 best solutions below

0
Martin On

You're doing javascript. You have to go to py3.codeskulptor.org. Your code works fine there.

0
Olivier Pirson On

The module time in CodeSkulptor implements only the time function: http://www.codeskulptor.org/docs.html#Time

See the content of the module: http://www.codeskulptor.org/#user44_uEhmhATcPLOytns.py

The documentation of CodeSkulptor3 mentions only the time function in the time module: http://py3.codeskulptor.org/docs.html#Time

But the sleep function and other functions are present in the implementation: http://py3.codeskulptor.org/#user301_4e5WktRmz4A193D.py

Note that in CodeSkulptor3 all printing waits the end of the sleep function. So this function is probably useless if you want wait before to print.