New submission from YasirA <[email protected]>:
In the Template example, there's no placeholder to be substituted with date. I
think it should be rewritten along the following lines:
>>> import time, os.path
>>> photofiles = ['img_1074.jpg', 'img_1076.jpg', 'img_1077.jpg']
>>> class BatchRename(Template):
... delimiter = '%'
>>> fmt = input('Enter rename style (%d-date %n-seqnum %f-format): ')
Enter rename style (%d-date %n-seqnum %f-format): Ashley_%d%n%f
>>> t = BatchRename(fmt)
>>> date = time.strftime('%d%b%y')
>>> for i, filename in enumerate(photofiles):
... base, ext = os.path.splitext(filename)
... newname = t.substitute(d=date+'_', n=i, f=ext)
... print('{0} --> {1}'.format(filename, newname))
img_1074.jpg --> Ashley_0.jpg
img_1076.jpg --> Ashley_1.jpg
img_1077.jpg --> Ashley_2.jpg
Yasir.
----------
assignee: docs@python
components: Documentation
messages: 338714
nosy: YasirA, docs@python
priority: normal
severity: normal
status: open
title: Brief Tour of the Standard Library — Part II example problem
versions: Python 3.7
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36413>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com