[Python-ideas] Add __main__ for uuid, random and urandom
k7hoven at gmail.com
Sat Apr 2 02:37:39 EDT 2016
On Fri, Apr 1, 2016 at 8:41 PM, Michel Desmoulin <desmoulinmichel at gmail.com>
> 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
How about something like
python --me module expression_in_module_namespace
python --me random "randint(0,10)"
python --me module expression_assuming_module_is_imported
python --me random "random.randint(0,10)"
python -e "random.randint(0,10)"
which would automatically import stdlib if their names appear in the
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas