Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #67822 > unrolled thread
| Started by | Francis Moreau <francis.moro@gmail.com> |
|---|---|
| First post | 2014-03-05 09:07 +0100 |
| Last post | 2014-03-05 09:07 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Decoding a process output Francis Moreau <francis.moro@gmail.com> - 2014-03-05 09:07 +0100
| From | Francis Moreau <francis.moro@gmail.com> |
|---|---|
| Date | 2014-03-05 09:07 +0100 |
| Subject | Re: Decoding a process output |
| Message-ID | <mailman.7799.1394006779.18130.python-list@python.org> |
On 03/04/2014 05:05 PM, Peter Otten wrote: > Francis Moreau wrote: > >> Hi, >> >> In my understanding (I'm relatively new to python), I need to decode any >> bytes data provided, in my case, by a shell command (such as findmnt) >> started by the subprocess module. The goal of my application is to parse >> the command outputs. >> >> My application runs only on linux BTW and should run fine on both python >> 2.7 and py3k. >> >> My question is when decoding the output bytes data of the external >> command, which encoding should I use ? >> >> Should I guess the encoding by inspecting LANG or any LC_* environment >> variables ? >> >> Should I force one of those environment variable to a specific value >> before running my external command ? >> >> Thanks for any tips. > > You can use locale.getpreferredencoding(), which seems to evaluate LANG: > > $ python3 -c 'import locale; print(locale.getpreferredencoding())' > UTF-8 > $ LANG= python3 -c 'import locale; print(locale.getpreferredencoding())' > ANSI_X3.4-1968 Hmm I'm confused here: when unsetting or changing LANG, the encoding is changed on the fly that makes me wonder which part of the linux system encodes the command output. I don't think it's the latter, is the libc ? Thanks
Back to top | Article view | comp.lang.python
csiph-web