Passing parameters from C# application to Python application [for using in gensim] in Visual Studio 2017 RRS feed

  • Question

  • Hi,

    I am a C# programmer and new in Python. Now I am working on Python form Visual Studio 2017.

    I have already written a program in C# to do some text processing tasks, but now I need to accomplish my work in python as it provides advanced functions for dealing with Natural Language Processing.

    Specifically, I need to pass a List<List> parameter from my C# application to the Python application.

    The passed parameter will be used instead of 'doc_term_matrix' in line 48 at the following python snippet: 

    Another issue to be handled is the casting of the different data types, as I want to import a List<List<double>>, as shown below, from C# to be used as the parameter returned from the 'dictionary.doc2bow(doc)'  function in python.

    I have no idea how to do so. So, please help me solve this issue.

    Thanks in advance.


    Aya Zoghby

    Monday, May 21, 2018 10:41 AM

All replies

  • You cannot pass structured data like that across process boundaries. Unless your Python app supports IPC like WCF, named pipes, etc. then all you can do is pass the data on the command line which means first converting it to a string representation and then having your Python app read the command line and convert it back to data. Alternatively I guess you could also store the data in a file and then have the Python app read it. Either way though you won't be able to simply pass .NET objects to Python.

    You might also consider looking at IronPython. Never used it myself but it supports .NET. If you target that then you might be able to create a type/class/whatever in IronPython that you can call directly from .NET which would then allow you to pass parameters like you really want to do. But that would be a better question for the Python folks.

    Michael Taylor http://www.michaeltaylorp3.net

    Monday, May 21, 2018 2:48 PM
  • Thank you so much for the reply.

    I will try it.

    Aya Zoghby

    Tuesday, May 22, 2018 2:37 PM