How Can I Call Python Code From Another Script?

apex1

Regular Member
Joined
May 29, 2015
Messages
217
Reaction score
182
I want to keep my main code short, and very organized. Is there any way I can call code from another script, similar to the way a PHP include is used in a HTML document?

il5kM60aRZW3SGGwx4Bl9A.png


My main script is 'New Project.py' and I want to pull in 'zzz.py'

How can I do that?

@Yildiz
 
@FreakenSEOsmh

You should definitely jump back into it. It will be fun to build some powerful projects once all the building blocks are ready to go (code snippets).

All you guys bringing high energy to the thread are making it even more fun and exiting! Thanks for that.
 
you can run your py script in php exec function.

Some like this:

Get variables from ssh command line in python script and work with it:
http://www.pythonforbeginners.com/system/python-sys-argv

Code:
param1 = sys.argv[1]
param2 = sys.argv[2]
[CODE]

Run from php:
[CODE]$ssh = exec("cd ".__DIR__."/py-dir/; python script.py param1 param2");[CODE]

$ssh - contain result of python script that runs
 
in zzz.py

Code:
def foo():
  print("foo")

in run.py
Code:
import zzz

zzz.foo()

And run it
Code:
python3 run.py

Import success!
 
Back
Top