-2
The function of this code is to read a txt file (let’s imagine that in this txt have two words: Beautiful house and, in the other line, dirty car), after reading, is created an output txt (Result.txt), with the variations of the words contained in the first txt(Ex: Beautiful House, BEAUTIFUL HOUSE, BEAUTIFUL HOUSE, CASABONITA, etc.). I can generate these results, but when I ask to read a txt that contains ten thousand more words, during the execution process it hangs and closes, thus generating the output of the files that managed to make the change until locking.
Follow the code below.
entrada = input('Caminho do txt p/ leitura >> ')
print('Arquivo carregado', '\n')
arq = open(entrada, 'r')
print('>> Processando', '\n')
saida = open('Resultado.txt', 'w')
for linha in arq:
if linha.strip().strip("\n"):
saida.writelines(linha.upper().strip() + '\n')
saida.writelines(linha.lower().title().strip() + '\n')
saida.writelines(linha.lower().strip() + '\n')
saida.writelines(linha.upper().replace(" ", "").strip() + '\n')
saida.writelines(linha.lower().title().replace(" ", "").strip() + '\n')
saida.writelines(linha.lower().replace(" ", "").strip() + '\n')
arq.close()
saida.close()
print('>> Processo Concluido')
in this case, use ". write" instead of ". writelines". The "writelines" method of files is done to write several strings that are within a sequence - for example, a list of file lines. Since a string is a sequence of strings of 1 character, by coincidence it works in this case - but it consumes a lot more resources. (shouldn’t brake, but this may be the cause)
– jsbueno
All box variations a string is the factorial of its length for example the phrase
mOça boNitA
generates 3628800 box combinations or consumes 3.5 MB of memory. If you do this for 10 thousand words you must be pressing the RAM.– Augusto Vasques
Well remembered. Now imagine the memory consumption and space to be used in
HD
if we tried to produce all possible combinations of uppercase and lowercase letters of said words, combined with hardware configuration restrictions?– Solkarped