Re: Decimal separator from python to C

"M." <[email protected]> Wed, 28 Mar 2012 12:09:09 -0300
Newsgroups gmane.comp.python.ctypes
Message-ID <CACd0G9wULON6O736ZObQrOjAvzbnq8pbr8pq31XYEAXJsYrNCw@mail.gmail.com>
Hi Walther, hi Nikki,

2012/3/28 niki <[email protected]>:
> On 28.03.2012 03:04, M. wrote:
>>
>> Hey,
>>
>> 2012/3/27 niki<[email protected]>:
>>>
>>> On 26.03.2012 23:32, M. wrote:
>>>>
>>>>
>>>> Hi all,
>>>>
>>>> I'm using ctypes as a wrapper from a Pyside program to a C program.
>>>> Everything goes smoothly till I have to pass values to the C function.
>>>> The C function receive the values correctly when using
>>>> ctypes.c_double(), but the separator _inside_ the C code changed from
>>>> . to , and that is REALLY weird. Printing the data from python it
>>>> shows that is a float, and inside the C code everything is declared
>>>> accordingly. printf inside the C code shows a comma , as the
>>>> separator, while a C code compiled using the same compiler on the same
>>>> system shows period . as the separator. Any clues? My locale is
>>>> pt_BR-UTF-8.
>>>
>>>
>>>
>>> Python sets locale as requested by user/os e.g. "pt_BR-UTF-8".
>>> Try to set it back to "C".
>>
>>
>> I'll try, but a C program with the same locale defined on the system
>> gives the correct output. And a standard python program represents
>> floating point variables using a period. How come ctypes would pass
>> the variables to the C code using a comma?
>
>
> ctypes.c_double is binary number and has no ascii content.
> Minimal C programs usually don't set locale.

I agree - never had anything similar to that, but alas, yes, I'm using
Pyside/Qt. Setting the locale to LC_NUMERIC and C solves the issue, at
least partially - still have to test more. But how and why this
behavior is happening? Any clues?

Thanks again

>
> Niki

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure