how to call python code from C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • paritosh mahana

    #1

    how to call python code from C#

    Hi all,
    How can I call python code from my C# code. One thing is to make an
    ..exe file of the python program and then try to call it from my C#
    code. But I don't like that idea. Is there any other way to do this.
    Like making a .dll file from the python code and somehow call it from
    C# program.But I couldn't find anything on this topic on the net.
    Actually my GUI is in C# and rest part is in python, and i need to
    call python from my C# program. Please correct me if I am wrong
    anywhere.
    thanks
    paritosh.
  • Peter Hansen

    #2
    Re: how to call python code from C#

    paritosh mahana wrote:[color=blue]
    > How can I call python code from my C# code. One thing is to make an
    > .exe file of the python program and then try to call it from my C#
    > code. But I don't like that idea. Is there any other way to do this.
    > Like making a .dll file from the python code and somehow call it from
    > C# program.But I couldn't find anything on this topic on the net.
    > Actually my GUI is in C# and rest part is in python, and i need to
    > call python from my C# program. Please correct me if I am wrong
    > anywhere.[/color]

    You could use ctypes or the pywin32 package to provide your
    Python code with an ActiveX interface. Then you could just
    use it via COM, like any other COM object. Lots of references
    available via Google if you want to learn more about this
    approach...

    -Peter

    Comment

    • Dave Brueck

      #3
      Re: how to call python code from C#

      Peter Hansen wrote:[color=blue]
      > paritosh mahana wrote:
      >[color=green]
      >> How can I call python code from my C# code.[/color][/color]
      [snip][color=blue]
      > You could use ctypes or the pywin32 package to provide your
      > Python code with an ActiveX interface. Then you could just
      > use it via COM, like any other COM object. Lots of references
      > available via Google if you want to learn more about this
      > approach...[/color]

      Lemme add my two cents and say that this approach works well.

      We have a component that uses ctypes and runs as a COM local server (its own
      ..exe) and we currently use it both from Internet Explorer and from a C#
      application. COM can be hairy initially, but if you have any experience with COM
      then this approach is pretty straightforward .

      -Dave

      Comment

      • just starting

        #4
        Re: how to call python code from C#

        Thanks for all your kind information. I haven't used COM objects so
        far.I think now I have to learn it.Anyway thanks a lot again.
        paritosh.


        On Mon, 24 Jan 2005 12:43:50 -0700, Dave Brueck
        <dave@pythonapo crypha.com> wrote:[color=blue]
        > Peter Hansen wrote:[color=green]
        > > paritosh mahana wrote:
        > >[color=darkred]
        > >> How can I call python code from my C# code.[/color][/color]
        > [snip][color=green]
        > > You could use ctypes or the pywin32 package to provide your
        > > Python code with an ActiveX interface. Then you could just
        > > use it via COM, like any other COM object. Lots of references
        > > available via Google if you want to learn more about this
        > > approach...[/color]
        >
        > Lemme add my two cents and say that this approach works well.
        >
        > We have a component that uses ctypes and runs as a COM local server (its own
        > .exe) and we currently use it both from Internet Explorer and from a C#
        > application. COM can be hairy initially, but if you have any experience with COM
        > then this approach is pretty straightforward .
        >
        > -Dave
        > --
        > http://mail.python.org/mailman/listinfo/python-list
        >[/color]

        Comment

        • Ryan Paul

          #5
          Re: how to call python code from C#

          On Tue, 25 Jan 2005 00:35:04 +0530, paritosh mahana wrote:
          [color=blue]
          > Hi all,
          > How can I call python code from my C# code. One thing is to make an
          > .exe file of the python program and then try to call it from my C#
          > code. But I don't like that idea. Is there any other way to do this.
          > Like making a .dll file from the python code and somehow call it from
          > C# program.But I couldn't find anything on this topic on the net.
          > Actually my GUI is in C# and rest part is in python, and i need to
          > call python from my C# program. Please correct me if I am wrong
          > anywhere.
          > thanks
          > paritosh.[/color]

          This may not be relevant, but if what you are looking for is a way to
          write a program for .NET with a language that doesnt suck, you might want
          to look at Boo (http://boo.codehaus.org/). I'm not sure if it can directly
          use winforms, but you can probably make native .net libraries with it that
          you can utilize from C#. Boo looks and feels almost exactly like
          Python, so the learning curve is minimal, and using it is very pleasant.

          -- SegPhault

          Comment

          Working...