Home > Blockchain >  Calling .py file within function
Calling .py file within function

Time:01-22

I want to run a py file within function.

I have a .py file that name is "style.py" and that file has some arguments such as "image", "gpu", "output" etc.

I run this .py file in terminal like: !python style.py -gpu 0 -image xyz.png -output abc.png

I want to run this file within function like:

def run_image_py():
   !python style.py -gpu 0 -image xyz.png -output abc.png

Thank you.

CodePudding user response:

You can use os module to run commands like you would in terminal.

So for your problem you could do this:

import os

def run_image_py():
   os.system("!python style.py - gpu 0 -image xyz.png -output abc.png")


And the function should return the process return value!

CodePudding user response:

you can do it with os module

import os

def run_image_py():
    os.system('!python style.py -gpu 0 -image xyz.png -output abc.png')
  • Related