Sep-19-2023, 08:01 AM
(This post was last modified: Sep-19-2023, 08:01 AM by garynewport.)
Just posted about my file not working and realised, as soon as I finished, that I already knew the solution.
However, I'd like a more flexible solution.
Some of my files are being encoded using UTF-16 LE, others are likely to be UTF-8 and variants inbetween.
So that I can read various files, how might I easily use the correct form of opening of a file, based upon the file's encoding?
For example, my original line of Python read:
To cater for the UTF=16 LE files, I adapted this to:
Which now means I cannot read in the older files.
However, I'd like a more flexible solution.
Some of my files are being encoded using UTF-16 LE, others are likely to be UTF-8 and variants inbetween.
So that I can read various files, how might I easily use the correct form of opening of a file, based upon the file's encoding?
For example, my original line of Python read:
1 |
file = open (datafile, 'r' ) |
1 |
file = open (datafile, 'r' , encoding = 'utf-16-le' ) |