I have several ascii files that contain '\ooo' strings which represent
the octal value for a character. I want to convert these files to
unicode, and I came up with the following script. But it seems to me
that there must be a much simpler way to do it. Could someone more
experienced suggest some improvements?
I want to convert a file eg. containing:
hello \326du
with the unicode file containing:
hello du
----------8<---------------------------------------
#!/usr/bin/python
import re, string, sys
if len(sys.argv) > 1:
file = open(sys.argv[1],'r')
lines = file.readlines( )
file.close()
else:
print "give a filename"
sys.exit()
def to_unichr(str):
oct = string.atoi(str .group(1),8)
return unichr(oct)
for line in lines:
line = string.rstrip(u nicode(line,'La tin-1'))
if re.compile(r'\\ \d\d\d').search (line):
line = re.sub(r'\\(\d\ d\d)', to_unichr, line)
line = line.encode('ut f-8')
print line
----------8<--------------------------------------- 2 4276
On 23 Dec 2004 18:41:57 -0800, rumours say that fl************@ gmail.com
might have written: I have several ascii files that contain '\ooo' strings which represent the octal value for a character. I want to convert these files to unicode, and I came up with the following script. But it seems to me that there must be a much simpler way to do it. Could someone more experienced suggest some improvements?
decoded_string = "\326du".decode ("string_escape ")
unicode_text = unicode(decoded _string, "latin-1")
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
On 23 Dec 2004 18:41:57 -0800, rumours say that fl************@ gmail.com
might have written: I have several ascii files that contain '\ooo' strings which represent the octal value for a character. I want to convert these files to unicode, and I came up with the following script. But it seems to me that there must be a much simpler way to do it. Could someone more experienced suggest some improvements?
(hope I cancelled the previous off-by-one-backslash post...)
your_string = "\\326du"
decoded_string = your_string.dec ode("string_esc ape")
unicode_text = unicode(decoded _string, "latin-1")
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sean McIlroy |
last post by:
I recently found out that unicode("\347", "iso-8859-1") is the
lowercase c-with-cedilla, so I set out to round up the unicode numbers
of the extra characters you need for French, and I found them all just
fine EXCEPT for the o-e ligature (oeuvre, etc). I examined the unicode
characters from 0 to 900 without finding it; then I looked at
www.unicode.org but the numbers I got there (0152 and 0153) didn't
work. Can anybody put a help on me wrt...
|
by: Maxim Kasimov |
last post by:
there are a few questions i can find answer in manual:
1. how to define which is internal encoding of python unicode strings (UTF-8, UTF-16 ...)
2. how to convert string to UCS-2
(Python 2.2.3 on freebsd4)
--
Best regards,
Maxim
|
by: Alphaboomer |
last post by:
I'm using the following code to retrieve a list of all the Categories
used by Microsoft Outlook:
sub test()
Dim objWSHShell As Object
Dim strCategoryList As Variant
Set objWSHShell = CreateObject("WScript.Shell")
strCategoryList = objWSHShell.RegRead_
("HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Categories\MasterList")
|
by: Gidi |
last post by:
Hi,
I'm writing a C# win application program, and i need to transfer my hebrew
letters from unicode to ascii, now if i use the ascii encoding it writes me
??? instead of the hebrew letter i've entered. I know what the Ascii value of
each letter, so i understood that i can transfer my string to BYTE and enter
the ascii value by myself. if someone has a better idea, i'll be happy to
hear about it.
how can i know the Unicode value of a...
|
by: Hugo Amselschlag |
last post by:
Hi there,
I've implemented a local system hook to suppress certain windows beeing
displayed by the axWebbrowser control. Now I need some more information
before I can decide, whether to suppress a window or not.
My callback function get a long pointer (lParam) to a structure which
contains further information. This structure is described at MSN as follows:
typedef struct tagCREATESTRUCT {
| |
by: bolly |
last post by:
Hi,
I've been putting Python data into a sqlite3 database as tuples but
when I retrieve them they come back as unicode data e.g
'u(1,2,3,4)'.How can I change it back to a tuple so I can use it as a
Python native datatype?
I have looked in the docs and seen there is a decode/encode method but
how do I do this?
Hope you can help.
|
by: jaks.maths |
last post by:
How to convert negative integer to hexadecimal or octal number?
Ex: -568
What is the equivalent hexadecimal and octal number??
|
by: Nikola Skoric |
last post by:
What I have is a bunch of text in arabic, and series of Unicode bytes
which represent those arabic words (like this: \'c2\'e4\'f6\'d3\'f3\'c9
\'f1). Now I have to figure out how to convert my arabic text to bunch
of \'somethings. If I understood Unicode correctly (and I'm not sure if
I did), I first have to figure out which encoding this is (UTF-16 or
UTF-32 or some other) and then convert the letters to their byte
representation. I think...
|
by: Michael Goerz |
last post by:
Hi,
I am writing unicode stings into a special text file that requires to
have non-ascii characters as as octal-escaped UTF-8 codes.
For example, the letter "Í" (latin capital I with acute, code point 205)
would come out as "\303\215".
I will also have to read back from the file later on and convert the
escaped characters back into a unicode string.
|
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |