• Forum
  • Lounge
  • [Python question] can't read from file i

 
[Python question] can't read from file in Jupyter notebook

Hi guys,

long time no post!! Been occupied with my new venture which is a pursuit to get a degree in artificial intelligence and machine learning. We've been using jupyter notebook(on ubuntu) for all of our work thus far.

I'm not sure if the problem is with writing or reading from the file. The (txt)file that I'm writing and reading to is extremely large, in the region of 3MB. When I try to read from the file, I get an error which says: I/O operation on closed file.

To be noted; I also try to open the file in a text editor(gedit) but the text editor just crashes... although, when I open the file through the terminal using vi, I can read the contents of the file without issue.

Has anyone experienced this issue before, or have any experience with using jupyter notebook with Debian?

Thanks


cell1 writing
1
2
3
4
5
6
7
8
9
10
11

// above is code that reads from a file given to us for research and populates a list with all the words using regex( it works)

file_output = open("xample_out","w+")

for word in cleaned_words:
    file_output.write(word + ' ')
    
file_output.close()
print("finished")


cell2 reading

1
2
3
4
5
6
7
8

inp = open('xample_out','r')

if not inp:
    print("error")

words = file_input.read().split(' ')
Last edited on
Well, you seem to have opened your filestream as "inp" ...
... and then tried to read from it as "file_input"
@lastchance oh man, do I feel stupid lol Should have caught that one myself, problem solved(sort of)... still curious as to why I can read the file from the terminal but not from gedit, hmmm.

Thanks :)
Topic archived. No new replies allowed.