0

How can I run a specific function from the Powershell (or, for that matter, any other) terminal? What is missing from my python file ?

I have a python file my_file.py :

def func1(): print('first function') def func2(): print('second function') 

I have tried running python -m my_file func2, but I am not getting the expected output. What am I missing?

1
  • Sorry about the initial mixup - I wasn't thinking straight. The duplicate target should now be correct. Commented Apr 20, 2024 at 19:07

2 Answers 2

1

You can execute arbitrary python statements using -c argument:

for example:

python -c "from my_file import *; func1()" 
Sign up to request clarification or add additional context in comments.

Comments

1

You can use python -c cmd:

py_file.py:

def func(): print ("test") 

run in Powershell:

python -c "from py_file import func; func()" // outputs test

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.