[Tutor] Hi all: How do I save a file in a designated folder?

Cameron Simpson cs at zip.com.au
Tue May 2 19:28:10 EDT 2017

On 03May2017 00:01, Alan Gauld <alan.gauld at yahoo.co.uk> wrote:
>On 02/05/17 19:09, Michael C wrote:
>> 1. How to name the file with time stamp.   e.g.   05012017.png and so forth.
>And so forth? I assume you mean
>MMDDYYYY.png format?
>You should read about the strftime function in the time
>(and datetime) module. Other functions thee will find
>the current date/time for you. Thee are examples on the
>documentation pages but if you get stuck come back
>with specific questioons.

Further to this, I would also advocate that you consider writing the timestamp 
from largest unit to smallest unit, like an ISO8601 timestamp, which typically 
looks like:



This has the advantage that a lexical sort (as in a typical directory listing 
or file glob) automatically arranges names in date order.

I'd also remark that the USA centric format (MMDDYYYY) that Alan inferred is 
particularly unfortunate in that (a) the rest of the world generally use 
DDMMYYYY so that the units come in increasing size and (b) doesn't sort very 
nicely at all. Of course, you might have meant 5th December 2017 above, so who 
knows? But the very ambiguity makes this one to avoid.

For numeric timestamps like yours I only ever use YYYYMMDD (or the obvious 
variants like YYYY-MM-DD etc). If I use another, I make the month a word (lousy 
for sorting and parsing, but clear to the human reader); I only do that in 
prose, not in filenames.

Cameron Simpson <cs at zip.com.au>

More information about the Tutor mailing list