Jump to content

Recommended Posts

Posted

Boas,

Fiz um script em python mas na altura de o testar apareceu-me o erro "pythonw.exe has stopped working". Este script abre um ficheiro de 1,8G e procura um string ... etc...etc.

Será que o python se está a queixar por falta de memória? Qual é a alternativa a abrir tudo de uma só vez.

Obrigado

tejano96

Posted

O problema não é abrir o ficheiro, isso é só um handle, o problema é tentares ler tudo para memória e trabalhares sobre isso.

Abre o ficheiro e lê em chuncks, trabalha esses chunks, descarta-os e depois passa ao próximo bloco.

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

  • 2 weeks later...
Posted

Podes também simplesmente optar por abrir o ficheiro e ler linha a linha:

for l in open('ficheiro.txt'):
  print l

Isto não lê o ficheiro todo para a memória. Podes é ter problemas se o que procuras está partido entre várias linhas, e aí, as sugestões anteriores são as melhores.

Boa sorte.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.