0

I followed all the directions in this post Running a python script within wordpress and I still cannot get a result to display.

<?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;
}

I uploaded hello.py and Python.php to the plugins folder and made sure the plugin was properly activated.

2
  • there is no line 21 in the code you show us. Commented Dec 5, 2019 at 8:04
  • Excuse me i edited the code. I tried a lot of changes and I was confused. I have no error with this code but I cannot get a display. I think that it cannot read the python file Commented Dec 5, 2019 at 8:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.