![](https://secure.gravatar.com/avatar/463a381eaf9c0c08bc130a1bea1874ee.jpg?s=120&d=mm&r=g)
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
![](https://secure.gravatar.com/avatar/3760cb8557c626fe10a62dc7a35f3f23.jpg?s=120&d=mm&r=g)
That might actually be because bool didn't exist in python way back then ;) I suspect its probably safe to fix it now. -Brian On 11/2/07 12:14 PM, "Michael Foord" <fuzzyman@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@python.org http://mail.python.org/mailman/listinfo/pythondotnet
-------------------------- Brian Lloyd brian.lloyd@revolutionhealth.com
![](https://secure.gravatar.com/avatar/463a381eaf9c0c08bc130a1bea1874ee.jpg?s=120&d=mm&r=g)
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@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@python.org http://mail.python.org/mailman/listinfo/pythondotnet
-------------------------- Brian Lloyd
brian.lloyd@revolutionhealth.com
participants (2)
-
Brian Lloyd
-
Michael Foord