On Fri, Apr 1, 2016 at 8:41 PM, Michel Desmoulin
It's dangerous to talk about a new feature the 1st of April, so I'll start by saying this one is not a joke.
I read recently a proposal to allow md5 hashing doing python -m hashlib md5 filename.
I think it's a great idea, and that can extend this kind of API to other parts of Python such as:
python -m random randint 0 10 => print(random.randin(0, 10)) python -m random urandom 10 => print(os.urandom(10)) python -m uuid uuid4 => print(uuid.uuid4().hex) python -m uuid uuid3 => print(uuid.uuid3().hex)
This brings back memories :). Back when I wasn't using Python yet, I ended up needing some stuff in a shell script that was available in Python. Then, as I basically did not know any Python, I had to (1) figure out how do that in Python, and (2) how the heck to get the result cleanly out of there. Especially step 2 may have been a waste of time, even if I did eventually find out that I could do python -c and that i could do stuff like "import foo; print bar(foo)". I ended up writing a tiny bash script that did the "import foo; print " part for me so I only had to do the `bar(foo)` part. If I had had to install a package, I probably would have just found another solution. How about something like python --me module expression_in_module_namespace python --me random "randint(0,10)" or python --me module expression_assuming_module_is_imported python --me random "random.randint(0,10)" Or even python -e "random.randint(0,10)" which would automatically import stdlib if their names appear in the expression. - Koos