0

i want to execute a python script on my server which execute and return a list of data. How can i execute python script by php and return back the python list data in php code.

for example. python_file.py

import os


def list_data():
    """
    this function will return a content list of path directory
    :return: 
    """
    path = 'C:/'
    my_list = os.listdir(path)
    return my_list

print list_data()
1
  • Could you edit question and show us what you have so far for your php code ? Commented May 26, 2016 at 9:00

2 Answers 2

1

use this:

<?php
    $data_list = `python path/to/python_file.py`;
?>
Sign up to request clarification or add additional context in comments.

Comments

0

With exec command you can execute a shell command.

http://php.net/manual/en/function.exec.php

So basically any script ( including python ) can be executed.

But using exec is not encouraged in web apps. It basically lets you run shell commands and execute them on the server. Most shared hosts come with it disabled.

Comments

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.