469,635 Members | 1,952 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,635 developers. It's quick & easy.

Determining encoding of a file

In Linux it's possible for filesystems to have a different encoding from
the system's setting. Given a filename, is there a (preferably) portable
way to determine its encoding?

--
TH * http://www.realh.co.uk
Feb 3 '07 #1
3 2187
In <sl**************@realh.co.uk>, Tony Houghton wrote:
In Linux it's possible for filesystems to have a different encoding from
the system's setting. Given a filename, is there a (preferably) portable
way to determine its encoding?
No.

Ciao,
Marc 'BlackJack' Rintsch

Feb 3 '07 #2
Tony Houghton <h@realh.co.ukwrites:
In Linux it's possible for filesystems to have a different encoding
from the system's setting. Given a filename, is there a (preferably)
portable way to determine its encoding?
If there were, PEP 263 would not be necessary.

<URL:http://www.python.org/dev/peps/pep-0263/>

It's possible to *guess*, with no guarantee of getting the right
answer; but it's far better to be explicitly *told* what the encoding
is.

--
\ "If we don't believe in freedom of expression for people we |
`\ despise, we don't believe in it at all." -- Noam Chomsky |
_o__) |
Ben Finney

Feb 3 '07 #3
In <ma***************************************@python. org>,
Ben Finney <bi****************@benfinney.id.auwrote:
Tony Houghton <h@realh.co.ukwrites:
>In Linux it's possible for filesystems to have a different encoding
from the system's setting. Given a filename, is there a (preferably)
portable way to determine its encoding?

If there were, PEP 263 would not be necessary.

<URL:http://www.python.org/dev/peps/pep-0263/>

It's possible to *guess*, with no guarantee of getting the right
answer; but it's far better to be explicitly *told* what the encoding
is.
That seems to be specific to the encoding used in py source files
anyway. What I want to be able to do is guess the encoding of any file
for loading into a text editor based on gtksourceview which is pure
utf-8. The best I can do is assume it's in the system encoding with
locale.getdefaultlocale()[1]. Come to think of it, I wouldn't really be
any better off knowing if the filesystem has a diferent encoding anyway
because it doesn't necessarily determine what's used in the contents of
its files, only its filenames. And Linux at least seems to be able to
translate those on the fly.

--
TH * http://www.realh.co.uk
Feb 4 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Rajorshi | last post: by
reply views Thread by Chris McDonough | last post: by
4 posts views Thread by =?ISO-8859-1?Q?Nordl=F6w?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.