Python Forum
Stopwatch in Python/IPython shell - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Stopwatch in Python/IPython shell (/thread-11386.html)



Stopwatch in Python/IPython shell - suvadip - Jul-06-2018

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


RE: Stopwatch in Python/IPython shell - buran - Jul-06-2018

(Jul-06-2018, 06:24 AM)suvadip Wrote: I want to make it look a bit fancy.
check https://pypi.org/project/progressbar2/


RE: Stopwatch in Python/IPython shell - suvadip - Jul-06-2018

Thank you very very much!


RE: Stopwatch in Python/IPython shell - snippsat - Jul-06-2018

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]