Skip to content

Commit

Permalink
backwards import compat. for python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
rasbt committed Jan 26, 2014
1 parent a2db4ac commit f0155ae
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions pyprind/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Sebastian Raschka 01/25/2014
# PyPrind - Python Progress Indicator module

from pyprind.pyprind import ProgBar
from pyprind.pyprind import ProgPercent
from .progbar import ProgBar
from .progpercent import ProgPercent
38 changes: 2 additions & 36 deletions pyprind/pyprind.py → pyprind/progbar.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import time

class ProgBar()
class ProgBar():
""" Prints a progress bar to the standard output."""

def __init__(self, iterations, width=50):
Expand Down Expand Up @@ -34,38 +34,4 @@ def finish(self, cpu_time=True):
self.time[2] = self.time[1] - self.time[0]
sys.stdout.write('\n')
if cpu_time:
print('Time elapsed: {0:.4f} sec'.format(self.time[2]))


class ProgPercent():
""" Prints a progress of an computation as percentage to the standard output."""

def __init__(self, iterations):
self.cnt = 0
self.max_iter = float(iterations) # accommodation for Python 2.x users
self.perc = 0
self.time = [time.clock(), None, None]
self.__print_percent()

def __calc_percent(self):
return round(self.cnt/self.max_iter * 100)

def __print_percent(self):
sys.stdout.write('\r[%3d %%]' % (self.perc))

def update(self):
self.cnt += 1
next_perc = self.__calc_percent()
if next_perc > self.perc:
self.perc = next_perc
self.__print_percent()
sys.stdout.flush()

def finish(self, cpu_time=True):
self.time[1] = time.clock()
self.time[2] = self.time[1] - self.time[0]
sys.stdout.write('\n')
if cpu_time:
print('Time elapsed: {0:.4f} sec'.format(self.time[2]))


print('Time elapsed: {0:.4f} sec'.format(self.time[2]))
35 changes: 35 additions & 0 deletions pyprind/progpercent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import sys
import time

class ProgPercent():
""" Prints a progress of an computation as percentage to the standard output."""

def __init__(self, iterations):
self.cnt = 0
self.max_iter = float(iterations) # accommodation for Python 2.x users
self.perc = 0
self.time = [time.clock(), None, None]
self.__print_percent()

def __calc_percent(self):
return round(self.cnt/self.max_iter * 100)

def __print_percent(self):
sys.stdout.write('\r[%3d %%]' % (self.perc))

def update(self):
self.cnt += 1
next_perc = self.__calc_percent()
if next_perc > self.perc:
self.perc = next_perc
self.__print_percent()
sys.stdout.flush()

def finish(self, cpu_time=True):
self.time[1] = time.clock()
self.time[2] = self.time[1] - self.time[0]
sys.stdout.write('\n')
if cpu_time:
print('Time elapsed: {0:.4f} sec'.format(self.time[2]))


1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@
],
license='GPLv3',
long_description = README_TEXT,
extras_require={'testing': ['pytest']},
platforms='any',
)

0 comments on commit f0155ae

Please sign in to comment.