1

I am trying to use python -c command line option but cannot seem to make it work. What is the right way to use it? Sometime it is really useful to store the whole command and one line and make an alias for it then going into the interactive mode.

The following gives no output

-bash-3.2$ python -c "
import hashlib
hashlib.md5('test').hexdigest()"

But of course following works

-bash-3.2$ python
>>> import hashlib
>>> hashlib.md5('test').hexdigest()
'098f6bcd4621d373cade4e832627b4f6'
>>>

3 Answers 3

3

you've got to print what you want to see if in non-interactive mode.

python -c "import hashlib
print hashlib.md5('test').hexdigest()"

the interactive mode always prints the return values, but this is just a gimmick of the CLI

Sign up to request clarification or add additional context in comments.

Comments

2
python -c "import hashlib; print(hashlib.md5('test').hexdigest())"

Comments

1
>python -c "import hashlib; print hashlib.md5('test').hexdigest()"
098f6bcd4621d373cade4e832627b4f6

You are missing the print, which is why you don't see anything.

1 Comment

Hi, How can one deal with indentation while running python -c command. Suppose I want to run a try..except code.

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.