[python-win32] pb with string conversion to float and GetObject call

Moore, Paul Paul.Moore at atosorigin.com
Wed Sep 10 17:49:21 EDT 2003


From: popov [mailto:outlook at evpopov.com]

> Here's a strange one:
> 
> print float('8.4')
> 
> Works as expected.
> But:
> 
> import win32com.client
> obj = win32com.client.GetObject ("winmgmts:")
> print float('8.4')
> 
> Throws a 'ValueError: invalid literal for float(): 8.4' exception on the
> print line !
> If you use '8,4' instead of '8.4', then it works (!). So it seems that some
> locals have been modified here by the call to GetObject (without this call -
> leaving only the import statement - the problem does not show up).
> Note that using 'LDAP:' instead of 'winmgmts:', everything is ok. So maybe
> the culprit is the winmgmts provider...
> If someone could test this and let me know the results. Thx.

There's a discussion going on on python-dev at the moment (the messages
mention LC_NUMERIC in the subject) on basically this issue. Python's
float conversion routines rely on the underlying C locale remaining
unchanged. It's known that 3rd party extensions can violate this, and
also that Microsoft MAPI mucks up the locale behind the scenes. From
what you are reporting, it looks like the WMI stuff also does this.

I don't know of any fix for sure - you might be able to use the functions
from the locale module to set the locale value back to "C". Assuming that
an acceptable fix is found, something should be in Python 2.4 (I don't know
if the fix will be deemed appropriate for a maintenance release of 2.3).

Hope this helps,
Paul.

PS I'm copying this to python-dev, as evidence of another area where this
   issue comes up - I hope that's acceptable.



More information about the Python-win32 mailing list