473,545 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2315
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.ukw rites:
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************ *************** ************@py thon.org>,
Ben Finney <bi************ ****@benfinney. id.auwrote:
Tony Houghton <h@realh.co.ukw rites:
>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.getdefau ltlocale()[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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8268
by: Rajorshi | last post by:
Hello! How do I determine the encoding of a text file ? That is, given a text file I want to know the encoding it is in UTF8 or UTF16 or Latin etc. It would be very helpful if you could tell me how to do this in python on Linux. But just the method is acceptable. Thanks in advance!
1
1535
by: Jon Maz | last post by:
Hi, I am working on a dotnet url rewriting mechanism that has to be able to deal with urls containing non-standard characters, eg http://www.mysite.com/Télécharger. The problem is that some browsers will encode this url using utf8 & some using ISO 8859 (I *think* those are the only two possibilities). For ISO 8859 I can use the built-in...
0
1676
by: CTDev Team | last post by:
Hi, We are using Exchange Server 5.5, and have applications written in VB6 and C# that read and process emails. We are experiencing intermittent errors similar to C# Application System.Runtime.InteropServices.COMException (0x80004005): The client
1
3062
by: LP | last post by:
I need to figure encoding or code page of a file programmatically. Also I was asked to figure out what was the original encoding of different records stored as Unicode in SQL Server table. So, these records can be outputted to different files with original encodings. Can it be done? By the way, character encoding and code page are pretty...
4
19001
by: Nick | last post by:
Hi, I am trying to output a string of chinese characters as a text file. When I open a file for writing from VB, the file is automatically set to UTF-8 encoding (can tell by opening the file from notepad). However, when I open this file from a Chinese program that does not support unicode, garbage is displayed. So what I have to do is...
4
2048
by: Rémi | last post by:
Question: How can you determine the character set used by a webpage you built? My understanding of the issue is that the character set used by an HTML file (or any other file, for that matter) depends on your own system, and the encoding used by it; you cannot randomly insert a <META HTTP-EQUIV="Content-Type" content="text/html;...
0
1949
by: Chris McDonough | last post by:
ElementTree's XML serialization routine implied by tree._write(file, node, encoding, namespaces looks like this (elided): def _write(self, file, node, encoding, namespaces): # write XML to file tag = node.tag if tag is Comment: file.write("<!-- %s -->" % _escape_cdata(node.text, encoding)) elif tag is ProcessingInstruction:...
14
5744
by: Zoro | last post by:
My task is to read html files from disk and save them onto SQL Server database field. I have created an nvarchar(max) field to hold them. The problem is that some characters, particularly html entities, and French/German special characters are lost and/or replaced by a question mark. This is really frustrating. I have tried using StreamReader...
4
1505
by: =?ISO-8859-1?Q?Nordl=F6w?= | last post by:
How do I efficiently determine which possible encoding(s) a given text is in? Can I use the iconv.h api somehow? Thanks in advance, Nordlöw
0
7478
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7923
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7773
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5984
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4960
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
722
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.