> It would be better to write your own exception class:
>
> class MyException(Exception):
> pass
and how would i automatically inject this into 3rd part library
--
http://mail.python.org/mailman/listinfo/python-list
> except TypeError,e:
> print "1",e # is caught here
>
> 1 exceptions must be classes or instances, not str
doesn't happen so in 2.5.2
--
http://mail.python.org/mailman/listinfo/python-list
> try:
> raise "abc"
> except:
> e, t, tb = sys.exc_info()
> if not isinstance(e, str):
> raise
> print "caught", e
This seems to be the solution, thanks
--
http://mail.python.org/mailman/listinfo/python-list
but the whole point of catching such exception is that i can print its
value
there are many such exceptions and hence it is not feasible to catch
them all or know them all unless i go thru src code.
--
http://mail.python.org/mailman/listinfo/python-list
import sys
try:
raise "xxx"
except str,e:
print "1",e # is not caught here
except:# is caught here
print "2",sys.exc_type,sys.exc_value
In the above code a string exception is raised which though deprecated
but still a 3rd party library I use uses it. So how can I catch such
exception
On May 11, 10:47 am, Terry Reedy wrote:
> anuraguni...@yahoo.com wrote:
> > so unicode(obj) calls __unicode__ on that object
>
> It will look for the existence of type(ob).__unicode__ ...
>
> > and if it isn't there __repr__ is used
>
> According to the bel
yes but my list sometimes have list of lists
On May 10, 2:59 pm, "Diez B. Roggisch" wrote:
> anuraguni...@yahoo.com schrieb:
>
> > ok that explains it,
> > so
> > unicode(obj) calls __unicode__ on that object and if it isn't there
> > __repr__ is used
ok that explains it,
so
unicode(obj) calls __unicode__ on that object and if it isn't there
__repr__ is used
__repr__ of list by default return a str even if __repr__ of element
is unicode
so my only solution looks like to use my own list class everywhere i
use list
class mylist(list):
def __
and yes replace string by u'\N{COPYRIGHT SIGN}au'
as mentioned earlier non-ascii char may not come correct posted here.
On May 10, 9:19 am, "anuraguni...@yahoo.com"
wrote:
> First of all thanks everybody for putting time with my confusing post
> and I apologize for not
First of all thanks everybody for putting time with my confusing post
and I apologize for not being clear after so many efforts.
here is my last try (you are free to ignore my request for free
advice)
# -*- coding: utf-8 -*-
class A(object):
def __unicode__(self):
return u"©au"
sorry for not being specfic and not given all info
"""
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
'Linux-2.6.24-19-generic-i686-with-debian-lenny-sid'
"""
My question has not much to do with stdout because I am able to print
unicode
so
print uni
Sorry being unclear again, hmm I am becoming an expert in it.
I pasted that code as continuation of my old code at start
i.e
class A(object):
def __unicode__(self):
return u"©au"
def __repr__(self):
return unicode(self).encode("utf-8")
__str__ = __repr__
doesn't
also not sure why (python 2.5)
print a # works
print unicode(a) # works
print [a] # works
print unicode([a]) # doesn't works
--
http://mail.python.org/mailman/listinfo/python-list
#how can I print a list of object which may return unicode
representation?
# -*- coding: utf-8 -*-
class A(object):
def __unicode__(self):
return u"©au"
__str__ = __repr__ = __unicode__
a = A()
try:
print a # doesn't work?
except UnicodeEncodeError,e:
print e
try:
p
14 matches
Mail list logo