Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a specific function from a .py file from command line?

I have a tkinter GUI project. in this project I can load files and run tests on them. I would like to be able to write a script which does this from the command line. This means I need to run the main script, lets call it view.py and then run 2 callback functions from it, each one is a callback function for a button. Lets call this functions load(file), run(). These function are member functions of 2 different objects that are being created in the view.py script. Their names are load_button and run_button. How can I do that?

I can run the mainloop script view.py but dont know how to run functions that are defined in the file.

like image 973
evening Avatar asked Dec 31 '25 15:12

evening


1 Answers

In functionFile.py:

def sayHello():
    print("hello world")

CMD:

python -c "import functionFile; functionFile.sayHello()"

(you can also import every function or just specific ones: from functionFile import *; sayHello() or from functionFile import sayHello(); sayHello())

like image 102
LeDreamer Avatar answered Jan 02 '26 07:01

LeDreamer