Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7705197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:49:16+00:00 2026-05-31T23:49:16+00:00

I am reading a text file which I guess is encoded in utf-8. Some

  • 0

I am reading a text file which I guess is encoded in utf-8. Some lines can only be decoded as latin-1 though. I would say this is very bad practice, but nevertheless I have to cope with it.

I have the following questions:

First: how can I “guess” the encoding of a file? I have tried enca, but in my machine:

enca --list languages
belarussian: CP1251 IBM866 ISO-8859-5 KOI8-UNI maccyr IBM855 KOI8-U
  bulgarian: CP1251 ISO-8859-5 IBM855 maccyr ECMA-113
      czech: ISO-8859-2 CP1250 IBM852 KEYBCS2 macce KOI-8_CS_2 CORK
   estonian: ISO-8859-4 CP1257 IBM775 ISO-8859-13 macce baltic
   croatian: CP1250 ISO-8859-2 IBM852 macce CORK
  hungarian: ISO-8859-2 CP1250 IBM852 macce CORK
 lithuanian: CP1257 ISO-8859-4 IBM775 ISO-8859-13 macce baltic
    latvian: CP1257 ISO-8859-4 IBM775 ISO-8859-13 macce baltic
     polish: ISO-8859-2 CP1250 IBM852 macce ISO-8859-13 ISO-8859-16 baltic CORK
    russian: KOI8-R CP1251 ISO-8859-5 IBM866 maccyr
     slovak: CP1250 ISO-8859-2 IBM852 KEYBCS2 macce KOI-8_CS_2 CORK
    slovene: ISO-8859-2 CP1250 IBM852 macce CORK
  ukrainian: CP1251 IBM855 ISO-8859-5 CP1125 KOI8-U maccyr
    chinese: GBK BIG5 HZ
       none:

Which is not enough to detect latin-1. By the way: how can I increase the list of available languages for enca?

Second: is it possible to have a file partially encoded in different encodings? I think that, from a technical point of view, this is very much possible: just use different codecs for different parts of the file. Have you ever seen this? How would you handle reading such a file? Would you try to decode each line with a different encoding? How would you go about this? I am actually using python, and an example of handling multiple-encoding would be appreciated.

Third: how do you usually go about files for which you do not know the encoding that they are using? I encounter this problem often when downloading text files from different sources. They are usually CSV files exported from spreadsheets (I guess excel), but depending on the exporting parameters, they are using one encoding or another, without hints about which one has been chosen, so I am forced to guess.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:49:16+00:00Added an answer on May 31, 2026 at 11:49 pm
    1. Guess the text encoding a file – in what? Python, Perl, Java, C? Note that this sometimes produces unexpected results (e.g. the “bush hid the facts” bug)
    2. Sometimes a file will have text encoded in different encodings. Either the file format specifies different encodings for different parts in the file, or the format permits specifying an encoding switch. For example in MIME the headers keys are ascii, the header values can have embedded sections encoded in other encodings, and the encoding of the content is declared in the Content-Type header.
    3. If you don’t know the encoding you just have to read bytes from the file (in a binary safe manner) to a buffer until you can determine the encoding.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file which is encoded with codepage 850. I am reading
I am reading a text file which contains numbers in the range [1, 10^100].
I am reading a text file with this format: grrr,some text,45.4321,54.22134 I just have
What would be the most efficient method of reading a text file into a
When reading lines from a text file using python, the end-line character often needs
I'm reading in a large text file with 1.4 million lines that is 24
Here I'm reading text file which contains a integer in each line and I'm
I have an input text file which I am reading and storing everything in
I am reading and writting a structure into a text file which is not
I am reading a text file and processing some records, a relevant sample of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.