Calling Python code from inside php

alexelder at gmail.com alexelder at gmail.com
Wed Apr 23 15:13:40 EDT 2008


On Apr 23, 7:42 pm, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> vijay schrieb:
>
> > Hi
> >     I have a python code performing some computation for me.I have a
> > html page which passes certain argumnets to a php page.This php page
> > needs to pass on the value to the Python class and get the result
> > back.
> > How do I go about this??
>
> Write a commandline-app in python, that does the work for you. Invoke
> that using php.
>
> Or use something like pyphp - but I haven't used it, can't comment on
> its usability/support etc.
>
> Diez

A simple yet dangerous and rather rubbish solution (possibly more of a
hack than a real implementation) could be achieved by using a
technique described above:

<?php
        echo exec('python foo.py');
?>

I would look into pyphp though. This method has so many issues
attached to it it's hardly worth bothering with.
I'm with Nick when I say why on earth are you needing to call Python
from within PHP as opposed to using only Python or only PHP?

Alex.



More information about the Python-list mailing list