0

So I'm trying to figure out if i can get the variables that i make in Php file and use it in my Python file.

I've read that you can use this.

Php file:

$data='12';
$output=shell_exec("python pythonfile.py $data");
echo $output;

Python file:

import sys
print sys.argv[1]

And if i run the Php it will display 12

But what i want is to run it in Python, it's like I'll call $data in python and manipulate it like make it float number. Is this possible?

3
  • 1
    You should call your php script from your python script. Commented Jul 17, 2019 at 9:08
  • May i know how to do it? :) Commented Jul 17, 2019 at 9:09
  • 2
    Possible duplicate of Communication between PHP and Python Commented Jul 17, 2019 at 9:10

2 Answers 2

1

You should call your PHP script from your Python script, you can use subprocess module, and many other ways

import subprocess

subprocess.call("php /path/to/your/script.php")

Here have good example, and many others have in Google.

Sign up to request clarification or add additional context in comments.

2 Comments

apparently this doesn't find the file even tho they are in the same directory :O OSError: [Errno 2] No such file or directory
Try with var = ["php", "./path/to/your/script.php"] and then pas var subprocess.call(var)
1

A common and easy way to share data accross multiple process using different languages is to use sharable system resources. By exemple you could serialize data in a file and read the file from the other process. You can also use networks via sockets but it is more complicated.

1 Comment

that's sounds complicated already haha but will try to do read and do it. thanks!

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.