[Tutor] fileinput question

W W srilyk at gmail.com
Mon Aug 25 03:37:06 CEST 2008


On Sun, Aug 24, 2008 at 8:26 PM, Ezra Taylor <ezra.taylor at gmail.com> wrote:

> Hello all:
>                 Can I do the below with input() from fileinput?  If
> this is not possible, what can I do to create backup files with the
> date timestamp as an extension.  Thanks for you help all.
>
>
> from time import strftime
>
> for line in fileinput.input(inplace=1,backup='.strftime("%Y-%b-%d.%S")'
>           do something.
> --
>

filename = "myfile" + strftime("%Y-%b-%d.%S") + ".txt"
f = open(filename, "w")
mystring = "This is a file or something"
f.write(mystring)
f.close()

I assume strftime creates a string object so you can concatenate it.... but
that should give you what you need (or at least point you in the right
direction).

-Wayne
-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080824/10e7b002/attachment.htm>


More information about the Tutor mailing list