[Python.NET] Experimental C Extensions from IronPython with Python.NET - code and article
Michael Foord
fuzzyman at voidspace.org.uk
Wed Oct 24 14:54:47 CEST 2007
Sanghyeon Seo wrote:
> 2007/10/24, Michael Foord <fuzzyman at voidspace.org.uk>:
>
>> I've just posted the experimental code for accessing CPython extensions
>> from IronPython.
>>
>> Article: http://www.voidspace.org.uk/ironpython/cpython_extensions.shtml
>>
>> Comments, bugfixes and improvements welcomed!
>>
>
> * Strings from .NET come in as unicode on the CPython type
>
> An evil workaround is to define PyStringConvert as:
> def PyStringConvert(obj):
> # evil
> return PyString(obj).GetAttr('encode').Invoke()
>
Hmm.... definitely evil. :-) Maybe it could be conditional and if the
encode fails then leave it as unicode? All adds overhead for converting
data of course.
> This could be improved on Python.NET side. Any idea?
>
> * Can't yet pass in keyword args to function calls.
>
> This is related to the previous item, because:
>
>>>> def f(a): pass
>>>> f(**{u'a': 1})
>>>>
> TypeError: f() keywords must be strings
>
> With the previous workaround in place, replace PythonObject.__call__ with:
> def __call__(self, *args, **kw):
> args = ConvertToPy(args)
> kw = ConvertToPy(kw)
> return ConvertToIpy(self.real.Invoke(args, kw))
>
> This is more straightforward than creating PyObject[].
>
>
Definitely looks better. Thanks Seo.
Michael
More information about the PythonDotNet
mailing list