Skip to content
  • Hjem
  • Seneste
  • Etiketter
  • Populære
  • Verden
  • Bruger
  • Grupper
Temaer
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Kollaps
FARVEL BIG TECH
  1. Forside
  2. Ikke-kategoriseret
  3. What's a good way to detect file encoding in python that's not chardet?

What's a good way to detect file encoding in python that's not chardet?

Planlagt Fastgjort Låst Flyttet Ikke-kategoriseret
python
4 Indlæg 2 Posters 0 Visninger
  • Ældste til nyeste
  • Nyeste til ældste
  • Most Votes
Svar
  • Svar som emne
Login for at svare
Denne tråd er blevet slettet. Kun brugere med emne behandlings privilegier kan se den.
  • marcusxms@helvede.netM This user is from outside of this forum
    marcusxms@helvede.netM This user is from outside of this forum
    marcusxms@helvede.net
    wrote on sidst redigeret af
    #1

    What's a good way to detect file encoding in python that's not chardet?

    Really it's just to identify latin1 or similar, so perhaps I should just replace it with some specialized logic for that.

    #python

    inguin@nerdculture.deI marcusxms@helvede.netM 2 Replies Last reply
    0
    • marcusxms@helvede.netM marcusxms@helvede.net

      What's a good way to detect file encoding in python that's not chardet?

      Really it's just to identify latin1 or similar, so perhaps I should just replace it with some specialized logic for that.

      #python

      inguin@nerdculture.deI This user is from outside of this forum
      inguin@nerdculture.deI This user is from outside of this forum
      inguin@nerdculture.de
      wrote on sidst redigeret af
      #2

      @marcusxms
      Any byte sequence is valid latin1, so there's no reliable way to detect it. You can only guess, maybe with the help of dictionaries or at least tables of characters that commonly appear within words.

      Depending on your usecase it may be enough to test for ASCII and UTF-8 first, and assume latin1 if both fail.

      marcusxms@helvede.netM 1 Reply Last reply
      0
      • inguin@nerdculture.deI inguin@nerdculture.de

        @marcusxms
        Any byte sequence is valid latin1, so there's no reliable way to detect it. You can only guess, maybe with the help of dictionaries or at least tables of characters that commonly appear within words.

        Depending on your usecase it may be enough to test for ASCII and UTF-8 first, and assume latin1 if both fail.

        marcusxms@helvede.netM This user is from outside of this forum
        marcusxms@helvede.netM This user is from outside of this forum
        marcusxms@helvede.net
        wrote sidst redigeret af
        #3

        @inguin Alright, thanks for the tip!

        1 Reply Last reply
        0
        • marcusxms@helvede.netM marcusxms@helvede.net

          What's a good way to detect file encoding in python that's not chardet?

          Really it's just to identify latin1 or similar, so perhaps I should just replace it with some specialized logic for that.

          #python

          marcusxms@helvede.netM This user is from outside of this forum
          marcusxms@helvede.netM This user is from outside of this forum
          marcusxms@helvede.net
          wrote sidst redigeret af
          #4

          It seems one could use charset-normalizer at least in some cases.

          1 Reply Last reply
          0
          Svar
          • Svar som emne
          Login for at svare
          • Ældste til nyeste
          • Nyeste til ældste
          • Most Votes


          • Log ind

          • Har du ikke en konto? Tilmeld

          • Login or register to search.
          Powered by NodeBB Contributors
          Graciously hosted by data.coop
          • First post
            Last post
          0
          • Hjem
          • Seneste
          • Etiketter
          • Populære
          • Verden
          • Bruger
          • Grupper