Generating generations of files

Peter J. Holzer hjp-python at
Mon Apr 29 17:04:21 EDT 2019

On 2019-04-29 20:12:28 -0000, Grant Edwards wrote:
> On 2019-04-29, DL Neil <PythonList at> wrote:
> > Are you aware of a library/utility which will generate and maintain the 
> > file names of multiple generations of a file?
> Well, the FILES-11 filesystem on VAX/VMS did that automatically, but
> that's probably not too helpful. Though I guess Python is actually
> available for OpenVMS, and the porting of OpenVMS to AMD64 (aka
> x86-64) is progressing:

Until this is finished you could use something like this:


import os

def open11(file, mode, **kwargs):
    if "w" in mode:
            oldfile = os.readlink(file)
            basename, version = oldfile.split(";")
        except FileNotFoundError:
            basename = os.path.basename(file)
            version = 0
        newfile = basename + ";" + str(int(version) + 1)
        os.symlink(newfile, file)
    return open(file, mode, **kwargs)

if __name__ == "__main__":
    with open11("foo", "w") as f:

    with open11("foo", "w") as f:

    with open11("foo", "w") as f:


(WARNING: I haven't really tested this)


PS: I like Chris' suggestion to just use git. But it's IMHO only
practical if you plan to keep old versions for ever.

   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp at         | management tools.
__/   | | -- Ross Anderson <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <>

More information about the Python-list mailing list