1

In this example how to call "function func_call_from_terminal" from python terminal when the code running?

example: The name of the python script is "TEST.py"

def func_call_from_terminal():
 # in this function I need to print I_Value ... 
 # where this function must call from terminal during...
 # the running script TEST.py.
if __name__ == "__main__":
 I_Value = 1
 Flag = True
 while Flag :
 I_Value += 1
 if I_Value == 1e9
 Flag = False
asked Feb 4, 2022 at 16:37
7
  • 1
    What do you mean by the "python terminal"? If you're running a script, you need to put the function call in the script. Do you mean you want to interrupt the script while it's running? Commented Feb 4, 2022 at 16:43
  • Take a look at the KeyboardInterrupt exception. Commented Feb 4, 2022 at 16:44
  • My bad, I mean from terminal, no I won't interrupt the script I just need to call the function from terminal for example : >python func_call_from_terminal.py Commented Feb 4, 2022 at 17:05
  • You could make the script check sys.argv and call the function depending on the arguments. Commented Feb 4, 2022 at 17:13
  • What value of I? Commented Feb 4, 2022 at 17:36

1 Answer 1

3

Just open terminal and use this command

python -c 'import TEST; TEST.func_call_from_terminal()' 
answered Feb 4, 2022 at 17:42
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.