Determining encoding of a file

T

Tony Houghton

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?
 
M

Marc 'BlackJack' Rintsch

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
 
B

Ben Finney

Tony Houghton said:
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.
 
T

Tony Houghton

In <[email protected]>,
Ben Finney said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top