Calling python functions from C

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • robert.differentone@gmail.com

    Calling python functions from C

    I am a newbie to Python. I want to call python functions from C. I
    looked for examples but I couldn't get any simple one. Lets say my
    python code is :
    def add(a,b)
    return (a+b)

    I want to call add from C. Could anybody please help me? Thanks in
    advance.

    R.

  • Farshid Lashkari

    #2
    Re: Calling python functions from C

    robert.differen tone@gmail.com wrote:[color=blue]
    > I want to call add from C. Could anybody please help me?[/color]

    Look at the "Pure Embedding" section of the python documentation. It
    contains an example program that does exactly what you want. Here is a
    link to the page:

    The official home of the Python Programming Language


    -Farshid

    Comment

    • Ronny Mandal

      #3
      Re: Calling python functions from C

      On 9 May 2006 10:05:48 -0700, robert.differen tone@gmail.com wrote:
      [color=blue]
      >I am a newbie to Python. I want to call python functions from C. I
      >looked for examples but I couldn't get any simple one. Lets say my
      >python code is :
      >def add(a,b)
      > return (a+b)
      >
      >I want to call add from C. Could anybody please help me? Thanks in
      >advance.[/color]
      This is also known as "callback".

      Check out

      or
      The official home of the Python Programming Language


      -RM[color=blue]
      >
      >R.[/color]

      Comment

      • abhijitng@gmail.com

        #4
        Re: Calling python functions from C

        Thanks Farshid,

        Thats helps me alot !

        R.


        Farshid Lashkari wrote:[color=blue]
        > robert.differen tone@gmail.com wrote:[color=green]
        > > I want to call add from C. Could anybody please help me?[/color]
        >
        > Look at the "Pure Embedding" section of the python documentation. It
        > contains an example program that does exactly what you want. Here is a
        > link to the page:
        >
        > http://www.python.org/doc/ext/pure-embedding.html
        >
        > -Farshid[/color]

        Comment

        • abhijitng@gmail.com

          #5
          Re: Calling python functions from C

          Thanks Ronny,

          R.

          Ronny Mandal wrote:[color=blue]
          > On 9 May 2006 10:05:48 -0700, robert.differen tone@gmail.com wrote:
          >[color=green]
          > >I am a newbie to Python. I want to call python functions from C. I
          > >looked for examples but I couldn't get any simple one. Lets say my
          > >python code is :
          > >def add(a,b)
          > > return (a+b)
          > >
          > >I want to call add from C. Could anybody please help me? Thanks in
          > >advance.[/color]
          > This is also known as "callback".
          >
          > Check out
          > http://www.google.com/search?client=...utf-8&oe=utf-8
          > or
          > http://www.python.org/doc/current/ext/ext.html
          >
          > -RM[color=green]
          > >
          > >R.[/color][/color]

          Comment

          • Nigel Rowe

            #6
            Re: Calling python functions from C

            robert.differen tone@gmail.com wrote:
            [color=blue]
            > I am a newbie to Python. I want to call python functions from C. I
            > looked for examples but I couldn't get any simple one. Lets say my
            > python code is :
            > def add(a,b)
            > return (a+b)
            >
            > I want to call add from C. Could anybody please help me? Thanks in
            > advance.
            >
            > R.[/color]

            You might look at elmer <http://elmer.sourcefor ge.net/>

            Quote:
            What is elmer?
            Elmer is a tool which embeds a Python module into a C, C++, or Tcl
            application. The embedded Python module is used just as if it was
            written in the same language as the application itself, without
            requiring any knowledge of the Python/C API.

            Elmer generates "glue" code that embeds an interpreter for one type of
            language into an extension for another. Elmer allows function calls and
            various data types, both native and custom, to pass transparently
            between the two languages.


            --
            Nigel Rowe
            A pox upon the spammers that make me write my address like..
            rho (snail) swiftdsl (stop) com (stop) au

            Comment

            Working...