This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Brief Tour of the Standard Library — Part II example problem
Type: Stage: resolved
Components: Documentation Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: YasirA, docs@python, rhettinger
Priority: normal Keywords:

Created on 2019-03-24 05:06 by YasirA, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg338714 - (view) Author: (YasirA) Date: 2019-03-24 05:05
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.
msg338718 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-03-24 05:51
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.
History
Date User Action Args
2022-04-11 14:59:12adminsetgithub: 80594
2019-03-24 05:51:39rhettingersetstatus: open -> closed
resolution: not a bug
messages: + msg338718

stage: resolved
2019-03-24 05:45:17rhettingersetassignee: docs@python -> rhettinger

nosy: + rhettinger
2019-03-24 05:06:03YasirAcreate