[Python-ideas] Add __main__ for uuid, random and urandom

Victor Stinner victor.stinner at gmail.com
Fri Apr 1 15:07:41 EDT 2016


Hi,

2016-04-01 19:41 GMT+02:00 Michel Desmoulin <desmoulinmichel at gmail.com>:
> 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))

How many times did you need this feature recently? I don't recall
having to generate a random number in a range.


> python -m random urandom 10 => print(os.urandom(10))

I don't understand the use case. Can you elaborate?


> python -m uuid uuid4 => print(uuid.uuid4().hex)

FYI On Linux, you can use "cat /proc/sys/kernel/random/uuid" ;-)

I agree that -c is enough here:
./python -c 'import uuid; print(uuid.uuid4())'


> python -m uuid uuid3 => print(uuid.uuid3().hex)

I don't know UUID3. It looks like you need more parameters.


IMHO these use cases are not popular enough to justify a CLI.

hashlib CLI is inspired by existing tools: md5sum, sha1sum, etc. Same
rationale for Python tarfile CLI. What are the existing commands which
inspired your CLI?

Victor


More information about the Python-ideas mailing list