Adding a sequential letter to the end of a filename in Python -


i attempting write script name file user's username, date, unique identifier. objective network of users have file name generated them in standardized format in sequential order in shared database. able generate username , date, having trouble assigning identifier. thinking sequential ascii_lowercase, can not have duplicate.

examples: user doug saves 3 file edits on june 1, files should saved doug060115a, doug060115b, doug060115c. user doug saves 1 more file edit on june 2, file should save doug060215a.

so, unique identifier @ end of file name should start @ , if taken move on b, c, , forth. if username or date change unique identifier should start on @ a.

you can use offset of ord , slicing

def incrementname(s):     return s[:-1] + chr(ord(s[-1]) + 1)  >>> incrementname('doug060115b') 'doug060115c' 

not sure want once hit z (if anticipate case)


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -