tags:

views:

56

answers:

1

Hello all,

I know how to append date to the end of the file name, but I m not sure how can I later in script put that filename as a link to FTP server.

For instance:

import datetime

now = datetime.datetime.now()
suffix = now.strftime(""%d-%m-%Y, %H:%M"")
filename = 'My history(%s).txt'%suffix

How can I hard code it NOW variable so that I can manipulate with it later in script and that time is always the same as it was when it was added to variable.

+4  A: 

There is no need to 'hard code' the now variable so that it always references the same point of time. The now() function from the datetime library returns a datetime object; the values of the returned object will not change over time.

>>> import datetime
>>> import time
>>> x = datetime.datetime.now()
>>> x
datetime.datetime(2010, 8, 14, 16, 26, 6, 592441)
>>> time.sleep(5)
>>> x
datetime.datetime(2010, 8, 14, 16, 26, 6, 592441)
Andrew