1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] PHP, Python - Python get input from php plugin

Discussão em 'Python' iniciado por Stack, Maio 30, 2025.

  1. Stack

    Stack Membro Participativo

    I am working on a wordpress website and I vould like to use Python on one part of the backend. There is a file path which I need to change quite often and I vould like to change that in PHP code instead on Python code. Meaning that I want to insert file path in PHP script which runs the python code instead of in Python code.

    Here is my Python line of code:

    path = ('my_path')


    This is my php code:

    <?php # -*- coding: utf-8 -*-
    /* Plugin Name: Python embedded */

    add_shortcode( 'python', 'embed_python' );

    function embed_python( $attributes )
    {
    $data = shortcode_atts(
    [
    'file' => 'hello.py'
    ],
    $attributes
    );

    $handle = popen( __DIR__ . '/' . $data['file'], 'r' );
    $read = '';

    while ( ! feof( $handle ) )
    {
    $read .= fread( $handle, 2096 );
    }

    pclose( $handle );

    return $read;
    }


    So Inside this php file I want to insert a line in which I can put a file path here insead of in Python code. But i do need this path in my Python script so I need some sort of connection between php and python script.

    Continue reading...

Compartilhe esta Página