Skip to content

Commit

Permalink
Merge pull request glamp#46 from BoboTiG/fix-resource-leak
Browse files Browse the repository at this point in the history
Fix several ResourceWarnings: unclose file
  • Loading branch information
glamp authored Jan 2, 2019
2 parents 067247c + 53ee780 commit 23319fe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
8 changes: 5 additions & 3 deletions bashplotlib/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def read_numbers(numbers):
for number in numbers:
yield float(str(number).strip())
else:
for number in open(numbers):
yield float(number.strip())
with open(numbers) as fh:
for number in fh:
yield float(number.strip())


def run_demo():
Expand Down Expand Up @@ -106,7 +107,8 @@ def plot_hist(f, height=20.0, bincount=None, binwidth=None, pch="o", colour="def
pch = "o"

if isinstance(f, str):
f = open(f).readlines()
with open(f) as fh:
f = fh.readlines()

min_val, max_val = None, None
n, mean, sd = 0.0, 0.0, 0.0
Expand Down
16 changes: 9 additions & 7 deletions bashplotlib/scatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,22 @@ def plot_scatter(f, xs, ys, size, pch, colour, title):
title -- title of the plot
"""

cs = None
if f:
if isinstance(f, str):
f = open(f)

data = [tuple(line.strip().split(',')) for line in f]
with open(f) as fh:
data = [tuple(line.strip().split(',')) for line in fh]
else:
data = [tuple(line.strip().split(',')) for line in f]
xs = [float(i[0]) for i in data]
ys = [float(i[1]) for i in data]
if len(data[0]) > 2:
cs = [i[2].strip() for i in data]
else:
cs = None
else:
xs = [float(str(row).strip()) for row in open(xs)]
ys = [float(str(row).strip()) for row in open(ys)]
with open(xs) as fh:
xs = [float(str(row).strip()) for row in fh]
with open(ys) as fh:
ys = [float(str(row).strip()) for row in fh]

plotted = set()

Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

from setuptools import find_packages, setup

with open("README.rst") as fh:
long_description = fh.read()

setup(
name="bashplotlib",
version="0.6.5",
Expand All @@ -11,7 +14,7 @@
license="BSD",
packages=find_packages(),
description="plotting in the terminal",
long_description=open("README.rst").read(),
long_description=long_description,
entry_points = {
'console_scripts': [
'hist=bashplotlib.histogram:main',
Expand Down

0 comments on commit 23319fe

Please sign in to comment.