[Python.NET] [python] Re: FromManagedObject and Booleans

Michael Foord fuzzyman at voidspace.org.uk
Fri Nov 2 17:30:55 CET 2007


Brian Lloyd wrote:
> That might actually be because bool didn't exist in python way back
> then ;) I suspect its probably safe to fix it now.
>   
Cool. :-)

Michael
> -Brian
>
>
> On 11/2/07 12:14 PM, "Michael Foord" <fuzzyman at voidspace.org.uk> wrote:
>
>   
>> Hello all,
>>
>> I'm using the Python.Runtime assembly to provide access to CPython
>> modules from IronPython.
>>
>> I'm converting objects that pass from CPython to IronPython (and
>> vice-versa) by converting datatypes or proxying access.
>>
>> To convert to CPython types I use "PyObject.FromManagedObject(obj)"
>> where possible and do type specific conversion for other types.
>>
>> Unfortunately "PyObject.FromManagedObject(obj)" doesn't work for
>> booleans and passing in booleans to CPython doesn't result in 'True' or
>> 'False', but a 'System.Boolean' instead.
>>
>> As a workaround I'm using:
>>
>> @GIL
>> def _getBools():
>>     "Hack because 'FromManagedObject' doesn't work for bools"
>>     builtin = engine.ImportModule('__builtin__')
>>     return {False: builtin.GetAttr('False'), True: builtin.GetAttr('True')}
>>
>> _bools = _getBools()
>>
>> Is the fact that "PyObject.FromManagedObject(obj)" doesn't work for
>> booleans a bug? (Or is there an alternative method you can suggest?)
>>
>> All the best,
>>
>>
>> Michael Foord
>> http://www.manning.com/foord
>> _________________________________________________
>> Python.NET mailing list - PythonDotNet at python.org
>> http://mail.python.org/mailman/listinfo/pythondotnet
>>     
>
> --------------------------
> Brian Lloyd
>
> brian.lloyd at revolutionhealth.com
>
>
>   



More information about the PythonDotNet mailing list