Skip to content

Commit c8388f9

Browse files
committed
Close files or use safer access functions
1 parent f5da34f commit c8388f9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

examples/pylab_examples/mri_with_eeg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
dfile = cbook.get_sample_data('s1045.ima.gz')
2121
im = np.fromstring(dfile.read(), np.uint16).astype(float)
2222
im.shape = (256, 256)
23+
dfile.close()
2324

2425
# Plot the MRI image
2526
ax0 = fig.add_subplot(2, 2, 1)
@@ -41,7 +42,7 @@
4142
numSamples, numRows = 800, 4
4243
eegfile = cbook.get_sample_data('eeg.dat', asfileobj=False)
4344
print('Loading EEG %s' % eegfile)
44-
data = np.fromstring(open(eegfile, 'rb').read(), float)
45+
data = np.fromfile(eegfile, dtype=float)
4546
data.shape = (numSamples, numRows)
4647
t = 10.0 * np.arange(numSamples) / numSamples
4748

0 commit comments

Comments
 (0)