[Tutor] string formatting

eryksun eryksun at gmail.com
Wed Oct 24 23:24:33 CEST 2012


On Wed, Oct 24, 2012 at 4:11 PM, Mike <mike at froward.org> wrote:
>
> tar: /home/rev/code/beavis/test/24.10.2012: Cannot stat: No such file or
> directory
> tar: 15\:06\:52.tgz: Cannot stat: No such file or directory

You have a space in the filename:

    lt = time.localtime(time.time())
    return "%02d.%02d.%04d %02d:%02d:%02d" % (lt[2], lt[1], lt[0],
lt[3], lt[4], lt[5])

You could replace it with an underscore, or add double quotes around
the filename (e.g. "%s/%s.tgz"):

    package = 'tar zcvf %s "%s/%s.tgz"' % (fileTarg, dirTarg, timestamp())

Also, it's common to use time.strftime() to format a struct_time as a string.


More information about the Tutor mailing list