Re: Creating time stamps

2019-07-23 Thread Peter Pearson
On Mon, 22 Jul 2019 16:25:32 -0500, Michael F. Stemper wrote: > On 22/07/2019 15.58, Chris Angelico wrote: >> On Tue, Jul 23, 2019 at 6:34 AM Michael F. Stemper >> wrote: >>> [snip] >>> from datetime import datetime >>> from time import strftime >>> timestamp = datetime.now().strftime(

Re: Creating time stamps

2019-07-22 Thread Michael F. Stemper
On 22/07/2019 16.00, Stefan Ram wrote: > "Michael F. Stemper" writes: >> The first seems a little clunky with its accessing of multiple >> attributes, but the second has an additional import. Is there >> any reason to prefer one over the other? > > |>>> import datetime > |>>>

Re: Creating time stamps

2019-07-22 Thread MRAB
On 2019-07-22 22:41, Grant Edwards wrote: On 2019-07-22, Michael F. Stemper wrote: from datetime import datetime from time import strftime timestamp = datetime.now().strftime( "%Y-%m-%d %H:%M" ) [...] Apparently, the strftime() in that last line is not the one that I explicitly

Re: Creating time stamps

2019-07-22 Thread Grant Edwards
On 2019-07-22, Michael F. Stemper wrote: >>> from datetime import datetime >>> from time import strftime >>> timestamp = datetime.now().strftime( "%Y-%m-%d %H:%M" ) [...] > Apparently, the strftime() in that last line is not the one that I > explicitly imported, but a method of

Re: Creating time stamps

2019-07-22 Thread Michael F. Stemper
On 22/07/2019 15.58, Chris Angelico wrote: > On Tue, Jul 23, 2019 at 6:34 AM Michael F. Stemper > wrote: >> >> I have some code that generates a time-stamp as follows: >> >> from datetime import datetime >> tt = datetime.now() >> timestamp = "%4d-%02d-%02d %02d:%02d" % \ >> (tt.year,

Re: Creating time stamps

2019-07-22 Thread Albert-Jan Roskam
On 22 Jul 2019 23:12, Skip Montanaro wrote: Assuming you're using Python 3, why not use an f-string? >>> dt = datetime.datetime.now() >>> dt.strftime("%Y-%m-%d %H:%M") '2019-07-22 16:10' >>> f"{dt:%Y-%m-%d %H:%M}" '2019-07-22 16:10' ===》》 Or if you're running < Python 3.6 (no f strings):

Re: Creating time stamps

2019-07-22 Thread Skip Montanaro
Assuming you're using Python 3, why not use an f-string? >>> dt = datetime.datetime.now() >>> dt.strftime("%Y-%m-%d %H:%M") '2019-07-22 16:10' >>> f"{dt:%Y-%m-%d %H:%M}" '2019-07-22 16:10' Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: Creating time stamps

2019-07-22 Thread Chris Angelico
On Tue, Jul 23, 2019 at 6:34 AM Michael F. Stemper wrote: > > I have some code that generates a time-stamp as follows: > > from datetime import datetime > tt = datetime.now() > timestamp = "%4d-%02d-%02d %02d:%02d" % \ > (tt.year, tt.month, tt.day, tt.hour, tt.minute) > > I later

Creating time stamps

2019-07-22 Thread Michael F. Stemper
I have some code that generates a time-stamp as follows: from datetime import datetime tt = datetime.now() timestamp = "%4d-%02d-%02d %02d:%02d" % \ (tt.year, tt.month, tt.day, tt.hour, tt.minute) I later realized that I could have written it as: from datetime import datetime from