[Python-ideas] Provide __main__ for datetime and time
tjreedy at udel.edu
Fri Apr 1 15:55:38 EDT 2016
Note: new subjects should be posted as new threads. This was posted as
a response in the unrelated "`to_file()` method for strings" thread and
will not be seen by anyone who has killed that thread or who has threads
On 4/1/2016 2:02 PM, Michel Desmoulin wrote:
> As with my previous email about __main__ for random, uuid and os, I wish
> to suggest a similar __main__ for datetime.
File __main__ is for packages. I believe none of the modules you
mention are packages, so I presume you mean adding within the module
def main(args): ...
if __name__ = '__main__':
from sys import args
or the equivalent in C.
> The target audience may not
> be the same, so I'm making it a difference proposal.
> python -m datetime now => print(str(datetime.datetime.now())
> python -m datetime utcnow => print(str(datetime.datetime.utcnow())
> python -m time epoch => print(time.time())
> python -m datetime now "%d/%m/%Y" =>
> python -m datetime utcnow "%d/%m/%Y" =>
What is the particular motivation for this package? Should we add a
command line interface to math? So that
python -m math func arg => print(func(arg))
I am wondering what is or should be the general policy on the subject.
How easy is this for C-coded modules?
Terry Jan Reedy
More information about the Python-ideas