Skip to content

Instantly share code, notes, and snippets.

@ianfoo
Last active March 10, 2021 07:42
Show Gist options
  • Save ianfoo/93cd8d3be4409fcf2873fdc1a699d2d8 to your computer and use it in GitHub Desktop.
Save ianfoo/93cd8d3be4409fcf2873fdc1a699d2d8 to your computer and use it in GitHub Desktop.
Decode ISO-8859 encoded text to UTF-8
#! /usr/bin/env python2
# <bitbar.title>Escaped-Py2</bitbar.title>
# <bitbar.version>v0.0.1</bitbar.version>
# <bitbar.author.github>ianfoo</bitbar.author.github>
# <bitbar.desc>Echo escaped chars to stdout</bitbar.desc>
print("py2: :zzz: P\xe5 tide \xe5 logge av")
package main
import (
"fmt"
"os"
"os/exec"
"golang.org/x/text/encoding/charmap"
)
func main() {
c := exec.Cmd{Path: "001-escaped-py2.2s.py"}
stdout, err := c.Output()
if err != nil {
fmt.Fprintf(os.Stderr, "error running command: %w\n", err)
return
}
dec := charmap.ISO8859_1.NewDecoder()
output, err := dec.String(string(stdout))
fmt.Println(output)
}
❯ ./001-escaped-py2.2s.py
py2: :zzz: P� tide � logge av
❯ go run decode-it.go
py2: :zzz: På tide å logge av
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment