Python Forum
Stopwatch in Python/IPython shell
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stopwatch in Python/IPython shell
#1
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
Reply
#2
(Jul-06-2018, 06:24 AM)suvadip Wrote: I want to make it look a bit fancy.
check https://pypi.org/project/progressbar2/
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thank you very very much!
Reply
#4
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]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  IPython errors for numpy array min/max methods muelaner 1 508 Nov-04-2023, 09:22 PM
Last Post: snippsat
  Help creating shell scrip for python file marciokoko 10 1,258 Sep-16-2023, 09:46 PM
Last Post: snippsat
  Launch Python IDLE Shell from terminal Pavel_47 5 1,143 Feb-17-2023, 02:53 PM
Last Post: Pavel_47
  Can a program execute code in iPython shell and get result? deanhystad 3 1,663 Jun-17-2022, 03:45 AM
Last Post: Larz60+
  batch file for running python scipt in Windows shell MaartenRo 2 1,825 Jan-21-2022, 02:36 PM
Last Post: MaartenRo
  How to make a Python program run in a dos shell (cmd) Pedroski55 2 2,258 Nov-09-2020, 10:17 AM
Last Post: DeaD_EyE
Bug Python Shell 3.9.0 - Issue with indentation Earis 17 6,434 Oct-31-2020, 07:00 AM
Last Post: Earis
  IPython console vs Spyder script losc 3 2,673 Apr-30-2020, 04:57 AM
Last Post: deanhystad
  Python "Terminal" vs "Shell" SectionProperties 2 2,617 Apr-10-2020, 08:36 AM
Last Post: SectionProperties
  How can I create a multiline input in ipython? DataMower 3 4,307 Oct-28-2019, 08:50 PM
Last Post: DataMower

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020