Converting strings in Python

I am using Python 2.5. I imported a DLL built using the CLR. The DLL function returns a string. I am trying to apply the "partition" attribute to it. I can not do it. Even the section doesn't work. I think "all strings returned from CLR are returned as Unicode".

-3


source to share


2 answers


Could you please post a bug? Could you please post what type of object do you have ( type(yourvar)

)?

Please check if you have a method partition(sep)

for this object ( dir(yourvar)

).

The method application partition

should look like this:



>>> us=u", Unicode String!"
>>> us.partition(' ')
(u'\u041f\u0440\u0438\u0432\u0435\u0442,', u' ', u'Unicode String!')

      

You can also try split

instead partition

:

>>> from string import split
>>> split(us,' ',1)
[u'\u041f\u0440\u0438\u0432\u0435\u0442,', u'Unicode String!']

      

+2


source


If by CLR you mean .NET CLR , try using IronPython :

IronPython is a new implementation of the Python programming language that runs on .NET. It supports an interactive console with fully dynamic compilation. It integrates well with the rest of the .NET Framework and makes all .NET libraries available to Python programmers while maintaining full compatibility with the Python language.



In IronPython, loading (importing) and calling .NET dlls is well documented and straightforward.

+1


source







All Articles