<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Apr 1, 2016 at 8:41 PM, Michel Desmoulin <span dir="ltr"><<a href="mailto:desmoulinmichel@gmail.com" target="_blank">desmoulinmichel@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It's dangerous to talk about a new feature the 1st of April, so I'll<br>
start by saying this one is not a joke.<br>
<br>
I read recently a proposal to allow md5 hashing doing python -m hashlib<br>
md5 filename.<br>
<br>
I think it's a great idea, and that can extend this kind of API to other<br>
parts of Python such as:<br>
<br>
python -m random randint 0 10 => print(random.randin(0, 10))<br>
python -m random urandom 10 => print(os.urandom(10))<br>
python -m uuid uuid4 => print(uuid.uuid4().hex)<br>
python -m uuid uuid3 => print(uuid.uuid3().hex)<br>
<br></blockquote><div><br></div><div>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.<br></div><div><br></div><div>How about something like</div><div><br></div><div> python --me module expression_in_module_namespace</div><div><br></div><div> python --me random "randint(0,10)"</div><div><br></div><div>or </div><div><br></div><div> python --me module expression_assuming_module_is_imported</div><div><br></div><div> python --me random "random.randint(0,10)"</div><div><br></div><div><br></div><div>Or even</div><div><br></div><div> python -e "random.randint(0,10)"</div><div><br></div><div>which would automatically import stdlib if their names appear in the expression.</div><div><br></div><div>- Koos</div><div><br></div></div></div></div>