[python-win32] Feature request: adding unicode method to CDispatch

Tim Roberts timr at probo.com
Tue Oct 21 22:12:52 CEST 2008


Jacek Pliszka wrote:
> Would it be a problem to add __unicode__  method like this:
>
>        def __unicode__(self):
>            try:
>                return unicode(self.__call__())
>            except pythoncom.com_error, details:
>                if details[0] not in ERRORS_BAD_CONTEXT:
>                    raise
>                return self.__repr__()
>
> to class CDispatch in  win32com/client/dynamic.py   ?
>
> It would help me a lot - I need unicode data from objects.
>
> Or is there a way to get them ?
>   

Can you provide an example where the default behavior doesn't do what
you expect?  Usually, if a method is returning a string, it will be a
Unicode string, because that's the COM standard.  If a method returns a
single-byte string, it's probably better to convert it yourself.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list