Ciao.
Chiedo venia per l'incredibile bruttezza di questa gestione errore. Qui
il fatto è che, dando ad input il nome di un file che esiste, viene
comunque richiamato il blocco except.
Il semplice codice è questo:
fn = input("The document has to be encoded in UTF-8\nfilename.ext to
prepare? > ")
try:
f=open(fn, "rt",encoding="utf-8")
rig = f.readlines()
f.close()
print(f"File: {fn} found, with {len(rig)} lines of text.")
except:
print(f"Sorry, file: {fn} not found.\nRelaunch the App and try with
another filename.")
sys.exit()
Il file si chiama nvda.txt. L'ho appena creato io e sono assolutamente
certo del fatto che risieda nella stessa dir da cui lancio lo script.
Ciò nonostante viene richiamato il blocco except.
Come faccio a vedere che errore si genera oppure, c'è un possibile
motivo per cui non può aprire questo file, che è un testo semplice?
Gabry.
--
--
Gabriele Battaglia (IZ4APU)
Sent from my Asus VivobookPro15.
_______________________________________________
Python mailing list
Python@lists.python.it
https://lists.python.it/mailman/listinfo/python