Re: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

2015-05-12 Thread zljubisicmob
I would say so as well. Thanks to everyone who helped. Regards and best wishes. -- https://mail.python.org/mailman/listinfo/python-list

Re: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

2015-05-10 Thread Dave Angel
On 05/10/2015 05:10 PM, zljubisic...@gmail.com wrote: No, we can't see what ROOTDIR is, since you read it from the config file. And you don't show us the results of those prints. You don't even show us the full exception, or even the line it fails on. Sorry I forgot. This is the output of the

Re: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

2015-05-10 Thread zljubisicmob
> No, we can't see what ROOTDIR is, since you read it from the config > file. And you don't show us the results of those prints. You don't > even show us the full exception, or even the line it fails on. Sorry I forgot. This is the output of the script: C:\Python34\python.exe C:/Users/zoran/P

Re: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

2015-05-10 Thread zljubisicmob
> > It works, but if you change title = title[:232] to title = title[:233], > > you will get "FileNotFoundError: [Errno 2] No such file or directory". > > > Which is a *completely different* error from > > SyntaxError: 'unicodeescape' codec can't decode bytes in position 2-3: > truncated \U

Re: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

2015-05-09 Thread Chris Angelico
On Sun, May 10, 2015 at 1:13 AM, Steven D'Aprano wrote: > FileNotFoundError means that the program did run, it tried to open a file, > but the file doesn't exist. Normally it does, at least. Sometimes it means that a *directory* doesn't exist (for instance, you can get this when you try to create

Re: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

2015-05-09 Thread Steven D'Aprano
On Sat, 9 May 2015 08:31 pm, zljubisic...@gmail.com wrote: > It works, but if you change title = title[:232] to title = title[:233], > you will get "FileNotFoundError: [Errno 2] No such file or directory". Which is a *completely different* error from SyntaxError: 'unicodeescape' codec can't de

Re: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

2015-05-09 Thread Dave Angel
On 05/09/2015 06:31 AM, zljubisic...@gmail.com wrote: title = title[:232] title = title.replace(" ", "_").replace("/", "_").replace("!", "_").replace("?", "_")\ .replace('"', "_").replace(':', "_").replace(',', "_").replace('"', '')\ .replace('\n', '_'

Re: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

2015-05-09 Thread zljubisicmob
Steven, please do look at the code bellow: # C:\Users\zoran\PycharmProjects\mm_align\hrt3.cfg contents # [Dir] # ROOTDIR = C:\Users\zoran\hrt import os import shutil import configparser import requests import re Config = configparser.ConfigParser() Config.optionxform = str # preserve case in i

Re: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

2015-05-08 Thread Steven D'Aprano
string-literal containing \U is an escape sequence which expects exactly 8 hexadecimal digits to follow: py> path = '\U00a7' py> print(path) § If you don't follow the \U with eight hex digits, you get an error: py> path = '\Users~~~~' Fil

Re: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

2015-05-08 Thread Chris Angelico
On Sat, May 9, 2015 at 5:00 AM, wrote: > But it returns the following error: > > > C:\Python34\python.exe C:/Users/bckslash_test.py > File "C:/Users/bckslash_test.py", line 4 > ROOTDIR = 'C:\Users' > ^ > SyntaxError: (unicode error)

Re: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

2015-05-08 Thread zljubisicmob
Thanks for clarifying. Looks like the error message was wrong. On windows ntfs I had a file name more than 259 characters which is widows limit. After cutting file name to 259 characters everything works as it should. If I cut file name to 260 characters I get the error from subject which is wron

Re: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

2015-05-08 Thread MRAB
file1, file2) But it returns the following error: C:\Python34\python.exe C:/Users/bckslash_test.py File "C:/Users/bckslash_test.py", line 4 ROOTDIR = 'C:\Users' ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in

Re: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

2015-05-08 Thread random832
On Fri, May 8, 2015, at 15:00, zljubisic...@gmail.com wrote: > As I saw, I could solve the problem by changing line 4 to (small letter > "r" before string: > ROOTDIR = r'C:\Users\zoran' > > but that is not an option for me because I am using configparser in order > to read the ROOTDIR from underly

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

2015-05-08 Thread zljubisicmob
or: C:\Python34\python.exe C:/Users/bckslash_test.py File "C:/Users/bckslash_test.py", line 4 ROOTDIR = 'C:\Users' ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \U escape Process

Re: API for custom Unicode error handlers

2013-10-04 Thread Terry Reedy
On 10/4/2013 3:35 PM, Serhiy Storchaka wrote: 04.10.13 16:56, Steven D'Aprano написав(ла): I have some custom Unicode error handlers, and I'm looking for advice on the right API for dealing with them. I'm planning to built this error handler in 3.4 (see http://com

Re: API for custom Unicode error handlers

2013-10-04 Thread Serhiy Storchaka
04.10.13 16:56, Steven D'Aprano написав(ла): I have some custom Unicode error handlers, and I'm looking for advice on the right API for dealing with them. I have a module containing custom Unicode error handlers. For example: # Python 3 import unicodedata def namereplace_errors(ex

Re: API for custom Unicode error handlers

2013-10-04 Thread Serhiy Storchaka
04.10.13 20:22, Chris Angelico написав(ла): I'd be quite happy with importing having a side-effect here. If you import a module that implements a numeric type, it should immediately register itself with the Numeric ABC, right? This is IMO equivalent to that. There is a difference. You can't use

Re: API for custom Unicode error handlers

2013-10-04 Thread Ethan Furman
On 10/04/2013 06:56 AM, Steven D'Aprano wrote: Should the module holding the error handlers automatically register them? I think it should. Registration only needs to happen once, the module is useless without being registered, no threads nor processes are being started, and the only reason

Re: API for custom Unicode error handlers

2013-10-04 Thread Chris Angelico
On Fri, Oct 4, 2013 at 11:56 PM, Steven D'Aprano wrote: > Should the module holding the error handlers automatically register them? > In other words, if I do: > > import error_handlers > > just importing it will have the side-effect of registering the error > handlers. Normally, I dislike imports

API for custom Unicode error handlers

2013-10-04 Thread Steven D'Aprano
I have some custom Unicode error handlers, and I'm looking for advice on the right API for dealing with them. I have a module containing custom Unicode error handlers. For example: # Python 3 import unicodedata def namereplace_errors(exc): c = exc.object[exc.start] try:

Re: Right solution to unicode error?

2012-11-09 Thread wxjmfauth
Le jeudi 8 novembre 2012 21:42:58 UTC+1, Ian a écrit : > On Thu, Nov 8, 2012 at 12:54 PM, wrote: > > > Font has nothing to do here. > > > You are "simply" wrongly encoding your "unicode". > > > > > '\u2013' > > > '–' > > '\u2013'.encode('utf-8') > > > b'\xe2\x80\x93' > > '\

Re: Right solution to unicode error?

2012-11-08 Thread Andrew Berg
On 2012.11.08 08:06, Oscar Benjamin wrote: > It would be a lot better though if it just worked straight away > without me needing to set the code page (like the terminal in every > other OS I use). The crude equivalent of .bashrc/.zshrc/whatever shell startup script for cmd is setting a string valu

Re: Right solution to unicode error?

2012-11-08 Thread Oscar Benjamin
On 8 November 2012 19:54, wrote: > Le jeudi 8 novembre 2012 19:49:24 UTC+1, Ian a écrit : >> On Thu, Nov 8, 2012 at 11:32 AM, Oscar Benjamin >> >> wrote: >> >> > If I want the other characters to work I need to change the code page: >> >> > >> >> > O:\>chcp 65001 >> >> > Active code page: 65001

Re: Right solution to unicode error?

2012-11-08 Thread Ian Kelly
On Thu, Nov 8, 2012 at 1:54 PM, Prasad, Ramit wrote: > Why would font not matter? Unicode is the abstract definition > of all characters right? From that we map the abstract > character to a code page/set, which gives real values for an > abstract character. From that code page we then visually di

RE: Right solution to unicode error?

2012-11-08 Thread Prasad, Ramit
wxjmfa...@gmail.com wrote: > > Le jeudi 8 novembre 2012 19:49:24 UTC+1, Ian a écrit : > > On Thu, Nov 8, 2012 at 11:32 AM, Oscar Benjamin > > > > wrote: > > > > > If I want the other characters to work I need to change the code page: > > > > > > O:\>chcp 65001 > > > Active code page: 65001 > > >

Re: Right solution to unicode error?

2012-11-08 Thread Ian Kelly
On Thu, Nov 8, 2012 at 12:54 PM, wrote: > Font has nothing to do here. > You are "simply" wrongly encoding your "unicode". > '\u2013' > '–' '\u2013'.encode('utf-8') > b'\xe2\x80\x93' '\u2013'.encode('utf-8').decode('cp1252') > '–' No, it seriously is the font. This is what I ge

Re: Right solution to unicode error?

2012-11-08 Thread wxjmfauth
Le jeudi 8 novembre 2012 19:49:24 UTC+1, Ian a écrit : > On Thu, Nov 8, 2012 at 11:32 AM, Oscar Benjamin > > wrote: > > > If I want the other characters to work I need to change the code page: > > > > > > O:\>chcp 65001 > > > Active code page: 65001 > > > > > > O:\>Q:\tools\Python33\python

Re: Right solution to unicode error?

2012-11-08 Thread wxjmfauth
Le jeudi 8 novembre 2012 19:32:14 UTC+1, Oscar Benjamin a écrit : > On 8 November 2012 15:05, wrote: > > > Le jeudi 8 novembre 2012 15:07:23 UTC+1, Oscar Benjamin a écrit : > > >> On 8 November 2012 00:44, Oscar Benjamin > >> wrote: > > >> > On 7 November 2012 23:51, Andrew Berg wrote: > >

Re: Right solution to unicode error?

2012-11-08 Thread Ian Kelly
On Thu, Nov 8, 2012 at 11:32 AM, Oscar Benjamin wrote: > If I want the other characters to work I need to change the code page: > > O:\>chcp 65001 > Active code page: 65001 > > O:\>Q:\tools\Python33\python -c "import sys; > sys.stdout.buffer.write('\u03b1\n'.encode('utf-8'))" > α > > O:\>Q:\tools\

Re: Right solution to unicode error?

2012-11-08 Thread Oscar Benjamin
On 8 November 2012 15:05, wrote: > Le jeudi 8 novembre 2012 15:07:23 UTC+1, Oscar Benjamin a écrit : >> On 8 November 2012 00:44, Oscar Benjamin wrote: >> > On 7 November 2012 23:51, Andrew Berg wrote: >> >> On 2012.11.07 17:27, Oscar Benjamin wrote: >> >> >>> Are you using cmd.exe (standard Wi

Re: Right solution to unicode error?

2012-11-08 Thread wxjmfauth
Le jeudi 8 novembre 2012 15:07:23 UTC+1, Oscar Benjamin a écrit : > On 8 November 2012 00:44, Oscar Benjamin wrote: > > > On 7 November 2012 23:51, Andrew Berg wrote: > > >> On 2012.11.07 17:27, Oscar Benjamin wrote: > > >>> Are you using cmd.exe (standard Windows terminal)? If so, it does not

Re: Right solution to unicode error?

2012-11-08 Thread Oscar Benjamin
On 8 November 2012 00:44, Oscar Benjamin wrote: > On 7 November 2012 23:51, Andrew Berg wrote: >> On 2012.11.07 17:27, Oscar Benjamin wrote: >>> Are you using cmd.exe (standard Windows terminal)? If so, it does not >>> support unicode >> Actually, it does. Code page 65001 is UTF-8. I know that do

RE: Right solution to unicode error?

2012-11-08 Thread Anders Schneiderman
Right solution to unicode error? > > On 7 November 2012 22:17, Anders wrote: > > > > Traceback (most recent call last): > > File "outlook_tasks.py", line 66, in > > my_tasks.dump_today_tasks() > > File "C:\Users\Anders\code\Task List\t

Re: Right solution to unicode error?

2012-11-08 Thread Hans Mulder
On 8/11/12 00:53:49, Steven D'Aprano wrote: > This error confuses me. Is that an exact copy and paste of the error, or > have you edited it or reconstructed it? Because it seems to me that if > task.subject is a unicode string, as it appears to be, calling print on > it should succeed: > > py>

Re: Right solution to unicode error?

2012-11-08 Thread wxjmfauth
Le mercredi 7 novembre 2012 23:17:42 UTC+1, Anders a écrit : > I've run into a Unicode error, and despite doing some googling, I > > can't figure out the right way to fix it. I have a Python 2.6 script > > that reads my Outlook 2010 task list. I'm able to read t

Re: Right solution to unicode error?

2012-11-07 Thread Oscar Benjamin
On 7 November 2012 23:51, Andrew Berg wrote: > On 2012.11.07 17:27, Oscar Benjamin wrote: >> Are you using cmd.exe (standard Windows terminal)? If so, it does not >> support unicode > Actually, it does. Code page 65001 is UTF-8. I know that doesn't help > the OP since Python versions below 3.3 don

Re: Right solution to unicode error?

2012-11-07 Thread Steven D'Aprano
On Wed, 07 Nov 2012 14:17:42 -0800, Anders wrote: > I've run into a Unicode error, and despite doing some googling, I can't > figure out the right way to fix it. I have a Python 2.6 script that > reads my Outlook 2010 task list. I'm able to read the tasks from Outlook &g

Re: Right solution to unicode error?

2012-11-07 Thread Andrew Berg
On 2012.11.07 17:27, Oscar Benjamin wrote: > Are you using cmd.exe (standard Windows terminal)? If so, it does not > support unicode Actually, it does. Code page 65001 is UTF-8. I know that doesn't help the OP since Python versions below 3.3 don't support cp65001, but I think it's important to poin

Re: Right solution to unicode error?

2012-11-07 Thread Oscar Benjamin
On 7 November 2012 22:17, Anders wrote: > > Traceback (most recent call last): > File "outlook_tasks.py", line 66, in > my_tasks.dump_today_tasks() > File "C:\Users\Anders\code\Task List\tasks.py", line 29, in > dump_today_tasks > print task.subject > UnicodeEncodeError: 'ascii' codec

RE: Right solution to unicode error?

2012-11-07 Thread Prasad, Ramit
Anders wrote: > > I've run into a Unicode error, and despite doing some googling, I > can't figure out the right way to fix it. I have a Python 2.6 script > that reads my Outlook 2010 task list. I'm able to read the tasks from > Outlook and store them as a list of

Right solution to unicode error?

2012-11-07 Thread Anders
I've run into a Unicode error, and despite doing some googling, I can't figure out the right way to fix it. I have a Python 2.6 script that reads my Outlook 2010 task list. I'm able to read the tasks from Outlook and store them as a list of objects without a hitch. But when I t

Re: Why are some unicode error handlers "encode only"?

2012-03-11 Thread Terry Reedy
On 3/11/2012 10:37 AM, Steven D'Aprano wrote: At least two standard error handlers are documented as working for encoding only: xmlcharrefreplace backslashreplace See http://docs.python.org/library/codecs.html#codec-base-classes and http://docs.python.org/py3k/library/codecs.html Why is this?

Re: Why are some unicode error handlers "encode only"?

2012-03-11 Thread Walter Dörwald
On 11.03.12 15:37, Steven D'Aprano wrote: At least two standard error handlers are documented as working for encoding only: xmlcharrefreplace backslashreplace See http://docs.python.org/library/codecs.html#codec-base-classes and http://docs.python.org/py3k/library/codecs.html Why is this? I

Why are some unicode error handlers "encode only"?

2012-03-11 Thread Steven D'Aprano
At least two standard error handlers are documented as working for encoding only: xmlcharrefreplace backslashreplace See http://docs.python.org/library/codecs.html#codec-base-classes and http://docs.python.org/py3k/library/codecs.html Why is this? I don't see why they shouldn't work for decodi

Re: Unicode error in sax parser

2011-02-09 Thread Rickard Lindberg
On Tue, Feb 8, 2011 at 5:41 PM, Chris Rebert wrote: > On Tue, Feb 8, 2011 at 7:57 AM, Rickard Lindberg wrote: >> Hi, >> >> Here is a bash script to reproduce my error: > > Including the error message and traceback is still helpful, for future > reference. > >>    #!/bin/sh >> >>    cat > å.timeli

Re: Unicode error in sax parser

2011-02-09 Thread Stefan Behnel
Rickard Lindberg, 09.02.2011 14:01: Did you read my reply? Sorry, it was me who failed to read your question properly. Unicode file names aren't really working well, especially not in Py2.x. Python 3.2 provides many improvements here. I assume your file system encoding is UTF-8? What does sys

Re: Unicode error in sax parser

2011-02-09 Thread Rickard Lindberg
>> Did you read my reply? > >Sorry, it was me who failed to read your question properly. > >Unicode file names aren't really working well, especially not in Py2.x. >Python 3.2 provides many improvements here. > >I assume your file system encoding is UTF-8? What does >sys.getfilesystemencoding() giv

Re: Unicode error in sax parser

2011-02-09 Thread Stefan Behnel
Stefan Behnel, 09.02.2011 09:58: Rickard Lindberg, 09.02.2011 09:32: On Tue, Feb 8, 2011 at 5:41 PM, Chris Rebert wrote: Here is a bash script to reproduce my error: Including the error message and traceback is still helpful, for future reference. Thanks for pointing it out. #!/bin/sh ca

Re: Unicode error in sax parser

2011-02-09 Thread Stefan Behnel
Rickard Lindberg, 09.02.2011 09:32: On Tue, Feb 8, 2011 at 5:41 PM, Chris Rebert wrote: Here is a bash script to reproduce my error: Including the error message and traceback is still helpful, for future reference. Thanks for pointing it out. #!/bin/sh cat> å.timeline< EOF

Re: Unicode error in sax parser

2011-02-09 Thread Rickard Lindberg
On Tue, Feb 8, 2011 at 5:41 PM, Chris Rebert wrote: >> Here is a bash script to reproduce my error: > > Including the error message and traceback is still helpful, for future > reference. Thanks for pointing it out. >>    #!/bin/sh >> >>    cat > å.timeline < >>    EOF >> >>    python <>    # e

Re: Unicode error in sax parser

2011-02-08 Thread Stefan Behnel
Rickard Lindberg, 08.02.2011 16:57: Hi, Here is a bash script to reproduce my error: #!/bin/sh cat> å.timeline< 0.13.0devb38ace0a572b+ 2011-02-01 00:00:00 2011-02-03 08:46:00 asdsd

Re: Unicode error in sax parser

2011-02-08 Thread Chris Rebert
On Tue, Feb 8, 2011 at 7:57 AM, Rickard Lindberg wrote: > Hi, > > Here is a bash script to reproduce my error: Including the error message and traceback is still helpful, for future reference. >    #!/bin/sh > >    cat > å.timeline < >    EOF > >    python <    # encoding: utf-8 >    from xml.sa

Unicode error in sax parser

2011-02-08 Thread Rickard Lindberg
Hi, Here is a bash script to reproduce my error: #!/bin/sh cat > å.timeline < 0.13.0devb38ace0a572b+ 2011-02-01 00:00:00 2011-02-03 08:46:00 asdsd 2011-01-24 16:38:11

Re: Unicode error

2010-08-07 Thread kj
In <4c5d4ad9$0$28666$c3e8...@news.astraweb.com> Steven D'Aprano writes: >On Sat, 07 Aug 2010 19:28:56 +1200, Gregory Ewing wrote: >> Steven D'Aprano wrote: >>> "No memory? No disk space? No problem! Just a flesh wound!" What's >>> the point of that? >> >> +1 QOTW >While I'm always happy to

Re: Unicode error

2010-08-07 Thread Gregory Ewing
Steven D'Aprano wrote: "No memory? No disk space? No problem! Just a flesh wound!" What's the point of that? +1 QOTW -- http://mail.python.org/mailman/listinfo/python-list

Re: Unicode error

2010-08-06 Thread Steven D'Aprano
On Fri, 06 Aug 2010 11:23:50 +, kj wrote: > I don't get your point. Even when I *know* that a certain exception may > happen, I don't necessarily catch it. I catch only those exceptions for > which I can think of a suitable response that is *different* from just > letting the program fail.

Re: Unicode error

2010-08-06 Thread kj
In Nobody writes: >On Fri, 23 Jul 2010 10:42:26 +, Steven D'Aprano wrote: >> Don't write bare excepts, always catch the error you want and nothing >> else. >That advice would make more sense if it was possible to know which >exceptions could be raised. In practice, that isn't possible, a

Re: Unicode error

2010-08-04 Thread Aahz
In article , Nobody wrote: > >Java's checked exception mechanism was based on real-world experience of >the pitfalls of abstract types. And that experience was gained in >environments where interface specifications were far more detailed than is >the norm in the Python world. There are a number

Re: Unicode error

2010-07-25 Thread Nobody
On Sun, 25 Jul 2010 14:47:11 +, Steven D'Aprano wrote: >>> But in the >>> meanwhile, once you get an error, you know what it is. You can >>> intentionally feed code bad data and see what you get. And then maybe >>> add a test to make sure your code traps such errors. >> >> That doesn't really

Re: Unicode error

2010-07-25 Thread Steven D'Aprano
On Sun, 25 Jul 2010 13:52:33 +0100, Nobody wrote: > On Fri, 23 Jul 2010 18:27:50 -0400, Terry Reedy wrote: > >> But in the >> meanwhile, once you get an error, you know what it is. You can >> intentionally feed code bad data and see what you get. And then maybe >> add a test to make sure your cod

Re: Unicode error

2010-07-25 Thread Nobody
On Fri, 23 Jul 2010 18:27:50 -0400, Terry Reedy wrote: > But in the > meanwhile, once you get an error, you know what it is. You can > intentionally feed code bad data and see what you get. And then maybe > add a test to make sure your code traps such errors. That doesn't really help with exce

Re: Unicode error

2010-07-24 Thread John Machin
dirknbr gmail.com> writes: > I have kind of developped this but obviously it's not nice, any better > ideas? > > try: > text=texts[i] > text=text.encode('latin-1') > text=text.encode('utf-8') > except: > text=' ' As Steven has poin

Re: Unicode error

2010-07-23 Thread Steven D'Aprano
On Fri, 23 Jul 2010 22:46:46 +0100, Nobody wrote: > On Fri, 23 Jul 2010 10:42:26 +, Steven D'Aprano wrote: > >> Don't write bare excepts, always catch the error you want and nothing >> else. > > That advice would make more sense if it was possible to know which > exceptions could be raised.

Re: Unicode error

2010-07-23 Thread Terry Reedy
On 7/23/2010 5:46 PM, Nobody wrote: On Fri, 23 Jul 2010 10:42:26 +, Steven D'Aprano wrote: Don't write bare excepts, always catch the error you want and nothing else. That advice would make more sense if it was possible to know which exceptions could be raised. In practice, that isn't pos

Re: Unicode error

2010-07-23 Thread Thomas Jollans
On 07/23/2010 11:46 PM, Nobody wrote: > On Fri, 23 Jul 2010 10:42:26 +, Steven D'Aprano wrote: > >> Don't write bare excepts, always catch the error you want and nothing >> else. > > That advice would make more sense if it was possible to know which > exceptions could be raised. In practice,

Re: Unicode error

2010-07-23 Thread Benjamin Kaplan
On Fri, Jul 23, 2010 at 2:46 PM, Nobody wrote: > On Fri, 23 Jul 2010 10:42:26 +, Steven D'Aprano wrote: > >> Don't write bare excepts, always catch the error you want and nothing >> else. > > That advice would make more sense if it was possible to know which > exceptions could be raised. In pr

Re: Unicode error

2010-07-23 Thread Nobody
On Fri, 23 Jul 2010 10:42:26 +, Steven D'Aprano wrote: > Don't write bare excepts, always catch the error you want and nothing > else. That advice would make more sense if it was possible to know which exceptions could be raised. In practice, that isn't possible, as the documentation seldom

Re: Unicode error

2010-07-23 Thread Thomas Jollans
;results']: > ids.append(u[u'id']) > texts.append(u[u'text']) > > This is where texts comes from. > > When I then want to write texts to a file I get the unicode error. So your data is unicode? Good. Well, files are just streams of bytes

Re: Unicode error

2010-07-23 Thread dirknbr
.append(u[u'text']) This is where texts comes from. When I then want to write texts to a file I get the unicode error. Dirk -- http://mail.python.org/mailman/listinfo/python-list

Re: Unicode error

2010-07-23 Thread Chris Rebert
On Fri, Jul 23, 2010 at 3:14 AM, dirknbr wrote: > I am having some problems with unicode from json. > > This is the error I get > > UnicodeEncodeError: 'ascii' codec can't encode character u'\x93' in > position 61: ordinal not in range(128) Please include the full Traceback and the actual code th

Re: Unicode error

2010-07-23 Thread Steven D'Aprano
On Fri, 23 Jul 2010 03:14:11 -0700, dirknbr wrote: > I am having some problems with unicode from json. > > This is the error I get > > UnicodeEncodeError: 'ascii' codec can't encode character u'\x93' in > position 61: ordinal not in range(128) > > I have kind of developped this but obviously it

Unicode error

2010-07-23 Thread dirknbr
I am having some problems with unicode from json. This is the error I get UnicodeEncodeError: 'ascii' codec can't encode character u'\x93' in position 61: ordinal not in range(128) I have kind of developped this but obviously it's not nice, any better ideas? try: text=texts[

Re: Python 2.4 vs 2.5 - Unicode error

2009-01-22 Thread Gaurav Veda
On Jan 21, 7:08 pm, John Machin wrote: > > To replace non-ASCII characters in a UTF-8-encoded string by spaces: > | >>> u8 = ' and 25\xc2\xb0F' > | >>> u = u8.decode('utf8') > | >>> ''.join([chr(ord(c)) if c <= u'\x7f' else ' ' for c in u]) > | ' and 25 F' Thanks John for your reply. This is what

Re: Python 2.4 vs 2.5 - Unicode error

2009-01-21 Thread Wolfgang Rohdewald
On Mittwoch, 21. Januar 2009, Gaurav Veda wrote: > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position > 4357: ordinal not in range(128) > > Before sending the (insert) query to the mysql server, I do the > following which I think should've taken care of this problem: > sqlStr =

Re: Python 2.4 vs 2.5 - Unicode error

2009-01-21 Thread John Machin
On Jan 22, 9:50 am, Gaurav Veda wrote: > > The 0xc2 strongly suggests that you are feeding the beast data encoded > > in UTF-8 while giving it no reason to believe that it is in fact not > > encoded in ASCII. Curiously the first errant byte is a long way (4KB) > > into your data. Consider doing >

Re: Python 2.4 vs 2.5 - Unicode error

2009-01-21 Thread Gaurav Veda
> The 0xc2 strongly suggests that you are feeding the beast data encoded > in UTF-8 while giving it no reason to believe that it is in fact not > encoded in ASCII. Curiously the first errant byte is a long way (4KB) > into your data. Consider doing > print repr(data) > to see what you've actual

Re: Python 2.4 vs 2.5 - Unicode error

2009-01-21 Thread John Machin
On Jan 22, 4:49 am, Gaurav Veda wrote: > Hi, > > I am trying to put some webpages into a mysql database using python > (after some processing on the text). If I use Python 2.4.2, it works > without a fuss. However, on Python 2.5, I get the following error: > > UnicodeDecodeError: 'ascii' codec can

Python 2.4 vs 2.5 - Unicode error

2009-01-21 Thread Gaurav Veda
Hi, I am trying to put some webpages into a mysql database using python (after some processing on the text). If I use Python 2.4.2, it works without a fuss. However, on Python 2.5, I get the following error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 4357: ordinal not in

Re: odd unicode error

2007-04-12 Thread tubby
Martin v. Löwis wrote: >> path += '/' + b >> UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 1: >> ordinal not in range(128) >> >> Any ideas? > > path is a Unicode string, b is a byte string and contains the > byte \xd0. > > The problem is that you have a directory with f

Re: odd unicode error

2007-04-12 Thread Martin v. Löwis
> path += '/' + b > UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 1: > ordinal not in range(128) > > Any ideas? path is a Unicode string, b is a byte string and contains the byte \xd0. The problem is that you have a directory with file names in it that cannot be conver

odd unicode error

2007-04-12 Thread tubby
This: for root, dirs, files in os.walk(search_path): for f in files: print f ### Produces this: Traceback (most recent call last): File "/home/brad/Desktop/my_script.pyw", line 340, in -toplevel- hunt(target_files(search_path, skip_file_extensions(), skip_file

Re: Unicode error handler

2007-01-31 Thread Walter Dörwald
[EMAIL PROTECTED] wrote: > On Jan 30, 11:28 pm, Walter Dörwald <[EMAIL PROTECTED]> wrote: > >> codecs.register_error("transliterate", transliterate) >> >>Walter > > Really, really slick solution. > Though, why was it [:1], not [0]? ;-) No particular reason, unicodedata.normalize("NFD", ...)

Re: Unicode error handler

2007-01-31 Thread Walter Dörwald
Martin v. Löwis wrote: > Walter Dörwald schrieb: >> You might try the following: >> >> # -*- coding: iso-8859-1 -*- >> >> import unicodedata, codecs >> >> def transliterate(exc): >> if not isinstance(exc, UnicodeEncodeError): >> raise TypeError("don'ty know how to handle %r" % r)

Re: Unicode error handler

2007-01-31 Thread Gabriel Genellina
En Wed, 31 Jan 2007 01:21:49 -0300, [EMAIL PROTECTED] <[EMAIL PROTECTED]> escribió: > I don't understand what %r and r are and where they are from. The man > 3 printf page doesn't have %r formatting. Perhaps you should look into the Python docs instead? -- Gabriel Genellina -- http://mail.p

Re: Unicode error handler

2007-01-30 Thread Martin v. Löwis
Walter Dörwald schrieb: > You might try the following: > > # -*- coding: iso-8859-1 -*- > > import unicodedata, codecs > > def transliterate(exc): > if not isinstance(exc, UnicodeEncodeError): > raise TypeError("don'ty know how to handle %r" % r) > return (unicodedata.n

Re: Unicode error handler

2007-01-30 Thread [EMAIL PROTECTED]
On Jan 30, 11:28 pm, Walter Dörwald <[EMAIL PROTECTED]> wrote: > > codecs.register_error("transliterate", transliterate) > >Walter Really, really slick solution. Though, why was it [:1], not [0]? ;-) And one more thing: > def transliterate(exc): > if not isinstance(exc, UnicodeEncode

Re: Unicode error handler

2007-01-30 Thread Walter Dörwald
Rares Vernica wrote: > Hi, > > Does anyone know of any Unicode encode/decode error handler that does a > better replace job than the default replace error handler? > > For example I have an iso-8859-1 string that has an 'e' with an accent > (you know, the French 'e's). When I use s.encode('asci

Re: Unicode error handler

2007-01-26 Thread Rares Vernica
It does the job. Thanks a lot, Ray Peter Otten wrote: > Rares Vernica wrote: > >> Is there an encode/decode error handler that can replace all the >> not-ascii letters from iso-8859-1 with their closest ascii letter? > > A mapping, not an error handler, but it might do the job: > > http://effb

Re: Unicode error handler

2007-01-26 Thread Robert Kern
Rares Vernica wrote: > Is there an encode/decode error handler that can replace all the > not-ascii letters from iso-8859-1 with their closest ascii letter? No, but IBM's ICU library can transform one script to another in very flexible and capable ways. One such configuration can do what you ask.

Re: Unicode error handler

2007-01-26 Thread Peter Otten
Rares Vernica wrote: > Is there an encode/decode error handler that can replace all the > not-ascii letters from iso-8859-1 with their closest ascii letter? A mapping, not an error handler, but it might do the job: http://effbot.org/zone/unicode-convert.htm Peter -- http://mail.python.org/mail

Unicode error handler

2007-01-26 Thread Rares Vernica
Hi, Does anyone know of any Unicode encode/decode error handler that does a better replace job than the default replace error handler? For example I have an iso-8859-1 string that has an 'e' with an accent (you know, the French 'e's). When I use s.encode('ascii', 'replace') the 'e' will be rep

RE: Unicode Error

2006-08-23 Thread Tim Golden
[Gallagher, Tim (NE)] | Hey all I am learning Python and having a fun time doing so. | I have a question for y'all, it has to do with active directory. | I want to get the last login for a computer from Active | Directory. I am using the active_directory module and here | is my code. [START

Unicode Error

2006-08-22 Thread Gallagher, Tim (NE)
Hey all I am learning Python and having a fun time doing so.  I have a question for y'all, it has to do with active directory.   I want to get the last login for a computer from Active Directory.  I am using the active_directory module and here is my code.   [START

Re: unicode error

2006-03-17 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > I have this python code: > print >> htmlFile, " style=\"width: 200px; height:18px;\">"; > > > But that caues this error, and I can't figure it out why. Any help is > appreicate > File "./run.py", line 193, in ? > print >> htmlFile, " style=\"width: 200px; height:18

Re: unicode error

2006-03-17 Thread jean-michel bain-cornu
[EMAIL PROTECTED] wrote: > I have this python code: > print >> htmlFile, " style=\"width: 200px; height:18px;\">"; > > > But that caues this error, and I can't figure it out why. Any help is > appreicate > File "./run.py", line 193, in ? > print >> htmlFile, " style=\"width: 200px; height:18

unicode error

2006-03-17 Thread Allerdyce . John
I have this python code: print >> htmlFile, ""; But that caues this error, and I can't figure it out why. Any help is appreicate File "./run.py", line 193, in ? print >> htmlFile, ""; UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 9: ordinal not in range(128) Thanks.

Re: Unicode error in wx_gdi ?

2005-03-04 Thread Serge Orlov
Erik Bethke wrote: > Hello All, > > I still shaking out my last few bugs in my tile matching game: > > I am now down to one stumper for me: > 1) when I initialize wxPython > 2) from an exe that I have created with py2exe > 3) when the executable is located on the desktop as opposed to > somewhe

Unicode error in wx_gdi ?

2005-03-04 Thread Erik Bethke
Hello All, I still shaking out my last few bugs in my tile matching game: I am now down to one stumper for me: 1) when I initialize wxPython 2) from an exe that I have created with py2exe 3) when the executable is located on the desktop as opposed to somewhere on C or D directly 4) when My De