Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102751

Re: [SOLVED] There has to be a better way to split this string!

From Chris Kaynor <ckaynor@zindagigames.com>
Newsgroups comp.lang.python
Subject Re: [SOLVED] There has to be a better way to split this string!
Date 2016-02-09 18:02 -0800
Message-ID <mailman.15.1455069770.7749.python-list@python.org> (permalink)
References <56BA91B5.5090400@cajuntechie.org> <56BA9505.40900@cajuntechie.org> <85mvr972vv.fsf@benfinney.id.au> <56BA9942.9060904@cajuntechie.org>

Show all headers | View raw


On Tue, Feb 9, 2016 at 5:58 PM, Anthony Papillion <anthony@cajuntechie.org>
wrote:
>
> On 02/09/2016 07:47 PM, Ben Finney wrote:
> > Anthony Papillion <anthony@cajuntechie.org> writes:
> >
> >> On 02/09/2016 07:26 PM, Anthony Papillion wrote:
> >>> I am using datetime.now() to create a unique version of a filename.
> >>> […]
> >>
> >> Found the solution in strftime(). Exactly what I was looking for.
> >
> > For the task of making a unique filename, you should also consider the
> > ‘tempfile’ module in the standard library.
>
> I looked at tempfile. Unfortunately, the filename has to be both
> 'unique' and 'identifiable' to the original. So if I am using mydog.jpg
> as the source and I am adding something unique to it, it has to still
> have mydog.jpg in the filename. Tempfile, I think, doesn't allow an easy
> way to do that. So I'm just adding the exact date and time which is
> unique enough for my purposes.

Actually, it doe (untested, but I've used the feature in projects):

tempfile.TemporaryFile(prefix="mydog", suffix=".jpg")

Chris

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: [SOLVED] There has to be a better way to split this string! Chris Kaynor <ckaynor@zindagigames.com> - 2016-02-09 18:02 -0800

csiph-web