[Python.NET] Passing Dictionary from python to C#

Feihong Hsu hsu.feihong at yahoo.com
Wed Jun 11 15:09:20 CEST 2008


This is not supported. However, you can easily put the values of the  Python dictionary into a .NET dictionary object. Unfortunately I'm not at a computer that has Python.NET installed, but I believe the following would work:

--------------------------------------------

from System.Collections.Generic import Dictionary
from System import String

params = {"one": "1","two":"2"}   

dict1 = Dictionary[String, String]()
for k, v in param.iterkeys():
    dict1[k] = v

ret = Hello_Dict(dict1)

--------------------------------------------

Cheers,
Feihong


--- On Wed, 6/11/08, Kaveripakam, Sathish <Sathish.Kaveripakam at phonak.com> wrote:

> From: Kaveripakam, Sathish <Sathish.Kaveripakam at phonak.com>
> Subject: [Python.NET] Passing Dictionary from python to C#
> To: pythondotnet at python.org
> Date: Wednesday, June 11, 2008, 7:26 AM
> Hi,
>  
> i am trying to pass a dictinoary from python to C#. i am
> using python25
> with python.NET 2.0 alpha 2 files(python.Runtime.dll,
> clr.pyd). When i
> try to initiate function , i get an error saying
>  
> "TypeError: No method matches given arguments".
> Could someone confirm
> me, if this is supported?
>  
> Pythonfile:
>  
> main.py:
>  
> params = {"one":
> "1","two":"2"}    
>   
> ret = Hello_Dict(params)
>  
> C# file:
>  
> int Hello_Dict(Dictionary<String,String> params_=
> {
>  
> --;
> --;
> return 1;
> }
> 
> ******************** 
> Legal Notice: 
> The information in this electronic transmission may contain
> confidential or
> legally privileged information and is intended solely for
> the individual(s)
> named above. If you are not an intended recipient or an
> authorized agent,
> you are hereby notified that reading, distributing, or
> otherwise
> disseminating, copying or taking any action based on the
> contents of this
> transmission is strictly prohibited. Any unauthorized
> interception of this
> transmission is illegal under law. If you have received
> this transmission in
> error, please notify the sender by telephone [at the number
> indicated above/
> on +41 58 928 0101] as soon as possible and then destroy
> all copies of this
> transmission. 
> ********************_________________________________________________
> Python.NET mailing list - PythonDotNet at python.org
> http://mail.python.org/mailman/listinfo/pythondotnet


      


More information about the PythonDotNet mailing list