#1
  1. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,270
    Rep Power
    12

    Embedding Python code inside Joomla


    Hello,

    i want to ask you guys if there is a way to embed python code into joomla cms?

    Is there a way for those to technologies to work together?

    And if it is ca you show me an example please?
    What is now proved was once only imagined!
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,301
    Rep Power
    7170
    It's possible, but not very efficient.

    You can execute a Python script from PHP using the exec() function:
    PHP Code:
    exec("python /path/to/python-script.py"); 
    There are also a variety of similar PHP functions that can be used to accomplish the same thing with minor differences to the way input and output are handled (passthru, system, proc_open, backticks).

    The Python script will be executed using its command line interface - not using CGI (or similar) interface as you would have if the web server were directly executing the Python script. This means that the Python script will not have access to information about the HTTP request - GET/POST values, the client's IP address, the page URL, etc. You could pass this information from PHP to Python using command line parameters, a pipe, a temporary file or some other form of inter-process communication, but you need to pass each piece of required information explicitly.

    The reason this is inefficient is because every call to exec will spawn a whole new process for the Python script. That's a fairly expensive operation to do on every HTTP request (this is why servers like Apache and interfaces like Fast-CGI re-use child processes and threads instead of creating new ones). Additionally, if you have more than one call to exec, every single one is going to spawn a new process.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,270
    Rep Power
    12
    Thanks i have tried one week ago the

    Code:
    os.system( "python %s > %s % page, temp")
    but i had to replace the header form the html_output.

    I wanted to sue subprocess and i cpould but for some reason python3 doesnt utilize mySQLdb yet, so my app cant use Python3 interpreter just yet.
    Any ideas when this will happen?
    What is now proved was once only imagined!

IMN logo majestic logo threadwatch logo seochat tools logo