0
import os, sys, string
# coding: utf-8
from typing import TextIO
lista: TextIO = open("C:\\Users\\Eunice\\Desktop\\contas.txt", "r", encoding="utf-8")
print(lista.readlines())
linha = lista.readlines()
for linha in lista:
arquivo = open("C:\\Users\\Eunice\\Desktop\\siga\\seguindo\\user_-_data\\database\\login.ini", "w")
arquivo.write("[headers]" "\ntitle = Config File \n" "\ncompression = yes\n""\ncompression_level = 9\n" "\n[configuracoes]\n""\nlineedit_login = email\n""\nlineedit_senha = senha\n""\ntexteditcontas =", linha, "\n senha\n")
arquivo = open(arquivo, "r")
print(arquivo)
arquivo.close()
os.startfile(r"C:\Users\Eunice\Desktop\siga\siga2\seguindo.exe")`
I have this code, until the lista.readlines works, displays the list, but then only executes the os.startfile, I don’t know what to do
lista: TextIO = open(....shouldn’t belista = open(.....– Augusto Vasques
Basically, it is the same problem of the question indicated in the blue box above: when you call
readlines, it reads all the contents of the file, so when to call again or do thefor, there’s nothing left to read.– hkotsubo
Exchange your
for linha in lista:forwhile linha:that will work– Evilmaax
@Evilmaax
while linhadoesn’t solve (see) - the problem is he usedreadlines, which reads all the contents of the file, and then when it arrives at thefor, there’s nothing left to read. So either he just callsreadlinesonce (and inforit uses the returned list), or it does not usereadlinesand does thefordirectly.– hkotsubo
While you’re at it, consider using
withto open the files, because it ensures that they will be closed at the end. And how you open the output file every time inside thefor, and with the optionw, it will be overwritten at each iteration. If this is not the intention, open only once outside thefor– hkotsubo