1

I have a simple task and want to run command from the line. E.g.

python3 -c 'print(2*2)'

The issue is when I want to invoke a function and pass parameter to it. E.g I want to lower the string 'ABC'. I use

python3 -c 'print(x="ABC",x.lower())'

Hence my question: how could I pass string value to function when invoke python from command line?

1 Answer 1

1

Use sys.argv to obtain command-line arguments:

$ python3 -c "import sys; print(sys.argv[1].lower())" HELLO
hello
$
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.