471,350 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 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 3423
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

Post your reply

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

Similar topics

12 posts views Thread by Peter Wilkinson | last post: by
24 posts views Thread by ChaosKCW | last post: by
5 posts views Thread by Mike Currie | last post: by
19 posts views Thread by Thomas W | last post: by
10 posts views Thread by Samuel Karl Peterson | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.