473,389 Members | 1,093 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,389 software developers and data experts.

ascii codex, ordinal not in range(128)

My software reads the directories and files on a server and then determines what changes have been made.

I use python because I don't just blindly compare new and updated files but interpret the data into what jobs have been worked on etc.

I have code which is

if job in line:

and which has (for the first time) given the above error.
ordinal not in range(128)

Line is a file together with its path and the filename contains a strange character.

Reading about this problem I can overcome the problem by putting the code
line = unicode(line, "mbcs")
before the if job in line code.

But I am not sure this is the right thing to do. The file name is :-
._PowerMathâ,¢ PICT Image0001

Line is obtained by reading the directory on the server, output to a file and then read by python.

What is going on and is my software now tied to Windows? (If so how do I untie it?)
Jul 16 '07 #1
3 3732
bartonc
6,596 Expert 4TB
My software reads the directories and files on a server and then determines what changes have been made.

I use python because I don't just blindly compare new and updated files but interpret the data into what jobs have been worked on etc.

I have code which is

if job in line:

and which has (for the first time) given the above error.
ordinal not in range(128)

Line is a file together with its path and the filename contains a strange character.

Reading about this problem I can overcome the problem by putting the code
line = unicode(line, "mbcs")
before the if job in line code.

But I am not sure this is the right thing to do. The file name is :-
._PowerMathâ,¢ PICT Image0001

Line is obtained by reading the directory on the server, output to a file and then read by python.

What is going on and is my software now tied to Windows? (If so how do I untie it?)
AFAIK, this is portable:
Expand|Select|Wrap|Line Numbers
  1. >>> print u'._PowerMathâ,¢ PICT Image0001'
  2. ._PowerMathâ,¢ PICT Image0001
  3. >>> 
Jul 16 '07 #2
bartonc - not sure if your post is relevant..if so could you add a little more explanation?

Presumably if I have a line of code

Expand|Select|Wrap|Line Numbers
  1. s = '123456'
and

Expand|Select|Wrap|Line Numbers
  1. t = unicode('123456', 'mbcs')
then if I write

Expand|Select|Wrap|Line Numbers
  1. if s == t:
the answer is true? Even though s is probably stored in a different format?

And what is the internal format of the string, I thought python 2.5 used unicode, so why does it complain when a character is greater than 127.

Is there a way of making all the strings the same unicode codec, or is this even desirable. Should I convert of directory listings to one codec?

Will the 'mbcs' codec cause a problem if I transpose the software to unix?

Seems I have lots of questions!!
Jul 17 '07 #3
bartonc
6,596 Expert 4TB
bartonc - not sure if your post is relevant..if so could you add a little more explanation?

Presumably if I have a line of code

Expand|Select|Wrap|Line Numbers
  1. s = '123456'
and

Expand|Select|Wrap|Line Numbers
  1. t = unicode('123456', 'mbcs')
then if I write

Expand|Select|Wrap|Line Numbers
  1. if s == t:
the answer is true? Even though s is probably stored in a different format?

And what is the internal format of the string, I thought python 2.5 used unicode, so why does it complain when a character is greater than 127.

Is there a way of making all the strings the same unicode codec, or is this even desirable. Should I convert of directory listings to one codec?

Will the 'mbcs' codec cause a problem if I transpose the software to unix?

Seems I have lots of questions!!
1:
>>> s = '123456'
>>> t = unicode('123456', 'mbcs')
>>> s == t
True
>>> t = u'123456'
>>> s == t
True
>>> u = unicode('123456', 'mbcs')
>>> t == u
True
>>>

2:
## <coding=utf8>

See PEP 263

3:
Use unicode strings, as in the example
uStr = u'handle unicode chars' # note the u before the opening quote.

Did I miss any?
Jul 17 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Peter Wilkinson | last post by:
Hello tlistmembers, I am using the encoding function to convert unicode to ascii. At one point this code was working just fine, however, now it has broken. I am reading a text file that has is...
4
by: Robin Siebler | last post by:
I have no idea what is causing this error, or how to fix it. The full error is: Traceback (most recent call last): File "D:\ScriptRuntime\PS\Automation\Handlers\SCMTestToolResourceToolsBAT.py",...
2
by: Francach | last post by:
Hi, I don't know what I'm doing wrong here. I''m using Python 2.4 and py2exe. I get he following error: Traceback (most recent call last): File "notegui.pyc", line 34, in OnClose File...
24
by: ChaosKCW | last post by:
Hi I am reading from an oracle database using cx_Oracle. I am writing to a SQLite database using apsw. The oracle database is returning utf-8 characters for euopean item names, ie special...
5
by: Mike Currie | last post by:
Can anyone explain why I'm getting an ascii encoding error when I'm trying to write out using a UTF-8 encoder? Thanks Python 2.4.3 (#69, Mar 29 2006, 17:35:34) on win32 Type "help",...
19
by: Thomas W | last post by:
I'm getting really annoyed with python in regards to unicode/ascii-encoding problems. The string below is the encoding of the norwegian word "fødselsdag". I stored the string as "fødselsdag"...
1
by: ronrsr | last post by:
I have an MySQL database called zingers. The structure is: zid - integer, key, autoincrement keyword - varchar citation - text quotation - text I am having trouble storing text, as typed in...
10
by: Samuel Karl Peterson | last post by:
Greetings Pythonistas. I have recently discovered a strange anomoly with string.replace. It seemingly, randomly does not deal with characters of ordinal value 127. I ran into this problem while...
4
by: Oleg Parashchenko | last post by:
Hello, I'm working on an unicode-aware application. I like to use "print" to debug programs, but in this case it was nightmare. The most popular result of "print" was: UnicodeDecodeError:...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.