You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def read_data(filename):
f = zipfile.ZipFile(filename)
for name in f.namelist():
return f.read(name).split()
f.close()
def read_data(filename):
f = zipfile.ZipFile(filename)
for name in f.namelist():
return tf.compat.as_str(f.read(name)).split()
f.close()
There are two problems that these two versions of the function share:
The for loop is redundant since the return statement exits the loop (and the function) with the first file in the loop. Also, there is only one file within the zip file anyway.
Since the return statement exits the function early, it never executes the f.close() line. Therefore it doesn't get to close the file object properly.
I propose something like this instead:
def read_data(filename):
"""Extract the first file enclosed in a zip file as a list of words"""
with zipfile.ZipFile(filename) as f:
data = f.read(f.namelist()[0]).split()
return data
def read_data(filename):
"""Extract the first file enclosed in a zip file as a list of words"""
with zipfile.ZipFile(filename) as f:
data = tf.compat.as_str(f.read(f.namelist()[0])).split()
return data
I will submit a pull request with the proposed changes.
The text was updated successfully, but these errors were encountered:
The
read_data()
function that appears in the following files:Look like this:
There are two problems that these two versions of the function share:
return
statement exits the loop (and the function) with the first file in the loop. Also, there is only one file within the zip file anyway.f.close()
line. Therefore it doesn't get to close the file object properly.I propose something like this instead:
I will submit a pull request with the proposed changes.
The text was updated successfully, but these errors were encountered: