[New-bugs-announce] [issue36413] Brief Tour of the Standard Library — Part II example problem
YasirA
report at bugs.python.org
Sun Mar 24 01:06:03 EDT 2019
New submission from YasirA <yarsanukaev at gmail.com>:
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 at python
components: Documentation
messages: 338714
nosy: YasirA, docs at python
priority: normal
severity: normal
status: open
title: Brief Tour of the Standard Library — Part II example problem
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36413>
_______________________________________
More information about the New-bugs-announce
mailing list