Penso tu debba fare:

open(fn, "rt", encoding='utf-8')

Il 26/05/22 16:47, Gabriele Battaglia ha scritto:

Reply to Yuri's message, wrote on 26/05/2022 at 16:22:

Ciao,

 ci sarà un altro errore che fa scattare l'except. Prova ad eliminare il try/except ed esegui solo il blocco nel try, dovresti vedere l'errore.

 Solitamente conviene scrivere l'eccezione in maniera esplicita:

 except OSError:

 Se non è un errore sul file, allora vedrai il traceback e l'errore reale.


Grande Yuri, hai fatto centro, ma vorrei che fosse saltata fuori una cosa più semplice.

Avevi perfettamente ragione, l'errore l'ho visto, ma non ci capisco niente! Eccolo qui.

Me lo tradurresti? :)


***

e:\Dropbox\IZ4APU\CW>cwzer
        CWzer 1.0, may 26th, 2022 by Gabe, IZ4APU.
        This small utility takes a text file and prepare it to be converted
        in morse with other apps like Ebook2CW by DJ5CW.
Read 9 substitutions from file: CWzer_subs.txt
filename.ext to prepare? > r.txt
Traceback (most recent call last):
  File "E:\Dropbox\IZ4APU\CW\cwzer.py", line 38, in <module>
    rig = f.readlines()
  File "C:\Users\GBattaglia\AppData\Local\Programs\Python\Python310\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 4141: character maps to <undefined>

e:\Dropbox\IZ4APU\CW>


L'unica cosa che posso aggiungere è che, almeno mi pare, il file r.txt che sto cercando di aprire con open(nomefile, "r") è in UTF8


Grazie se mi sai o vuoi dare una dritta.


Gabry.

_______________________________________________
Python mailing list
Python@lists.python.it
https://lists.python.it/mailman/listinfo/python
_______________________________________________
Python mailing list
Python@lists.python.it
https://lists.python.it/mailman/listinfo/python

Rispondere a