Python Forum

Full Version: Stopwatch in Python/IPython shell
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

I am very new to this community. What I am trying to do is to show a dynamic stopwatch in Python/IPython shell (not in a separate window) while the code is running and I want the stopwatch to stop when the code stops so that we can tell the computation time by looking at the stopwatch. So far what I have done is this:
import time
start = time.time()
print "Hi everyone! Have a nice day!"

end = time.time()
Min = (end -start) // 60
sec = (end -start) % 60

print "Total computation time is %s Minutes %s Seconds" %(Min, sec)
This gives me the computation time in Minutes and seconds but I want to make it look a bit fancy.
Probably this question is not very useful for small python codes but probably will be useful for large codes.
I am using Ubuntu 16.04 LTS. Python 2.7.12 and Ipython 5.7.0

Thanking you,

Suvadip
(Jul-06-2018, 06:24 AM)suvadip Wrote: [ -> ]I want to make it look a bit fancy.
check https://pypi.org/project/progressbar2/
Thank you very very much!
Also look at tqdm
(Jul-06-2018, 06:24 AM)suvadip Wrote: [ -> ]I am using Ubuntu 16.04 LTS. Python 2.7.12 and Ipython 5.7.0
We do as always advice to switch to python 3.
Now do Ubuntu 16.04 comes with python 3.5,just need to use python3 and pip3.
Linux Python 3 environment

Python 3.7 has just has been released,and it do of course work there to.
Her both on Python 3.7 and IPython 6.4.0.
[Image: hYSjjg.jpg]