Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 452 characters in body
Source Link
Robᵩ
  • 169.5k
  • 20
  • 251
  • 323

It stopped because it ran out of memory. input.readlines() reads the entire file into memory before returning a list of the lines.

Instead, use input as an iterator. This only reads a few lines at a time, and returns them immediately.

Don't do this:

for line in input.readlines(): 

Do do this:

for line in input: 

Taking everyone's advice into account, your program becomes:

regex = re.compile(r"<http://dbtropes.org/resource/Film/.*?> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbtropes.org/resource/Main/.*?> \.") with open("dbtropes.nt", "rb") as input: with open("dbtropes-v2.nt", "a") as output for line in input: if regex.search(line): output.write(line) 

It stopped because it ran out of memory. input.readlines() reads the entire file into memory before returning a list of the lines.

Instead, use input as an iterator. This only reads a few lines at a time, and returns them immediately.

Don't do this:

for line in input.readlines(): 

Do do this:

for line in input: 

It stopped because it ran out of memory. input.readlines() reads the entire file into memory before returning a list of the lines.

Instead, use input as an iterator. This only reads a few lines at a time, and returns them immediately.

Don't do this:

for line in input.readlines(): 

Do do this:

for line in input: 

Taking everyone's advice into account, your program becomes:

regex = re.compile(r"<http://dbtropes.org/resource/Film/.*?> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbtropes.org/resource/Main/.*?> \.") with open("dbtropes.nt", "rb") as input: with open("dbtropes-v2.nt", "a") as output for line in input: if regex.search(line): output.write(line) 
Source Link
Robᵩ
  • 169.5k
  • 20
  • 251
  • 323

It stopped because it ran out of memory. input.readlines() reads the entire file into memory before returning a list of the lines.

Instead, use input as an iterator. This only reads a few lines at a time, and returns them immediately.

Don't do this:

for line in input.readlines(): 

Do do this:

for line in input: