简体   繁体   中英

Python --command command line option

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'
>>>

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM