[issue36413] Brief Tour of the Standard Library — Part II example problem

New submission from YasirA <yarsanukaev@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@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 <report@bugs.python.org> <https://bugs.python.org/issue36413> _______________________________________

Change by Raymond Hettinger <raymond.hettinger@gmail.com>: ---------- assignee: docs@python -> rhettinger nosy: +rhettinger _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue36413> _______________________________________

Raymond Hettinger <raymond.hettinger@gmail.com> added the comment: Thank you for the suggestion, but the point of having the input() is that the end user can select their own rename style with arbitrary text and either including or excluding possible data substitutions of their own choice. The photo processing software I was using at the time I wrote the example works just like this. ---------- resolution: -> not a bug stage: -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue36413> _______________________________________
participants (2)
-
Raymond Hettinger
-
YasirA