Still \'diving in\' to Python, and want to make sure I\'m not overlooking something. I wrote a script that extracts files from several zip files, and saves the extracted files t
Yes, this is a good strategy for readable but unique filenames.
One important change: You should replace os.path.isfile
with os.path.lexists
! As it is written right now, if there is a directory named /foo/bar.baz, your program will try to overwrite that with the new file (which won't work)... since isfile
only checks for files and not directories. lexists
checks for directories, symlinks, etc... basically if there's any reason that filename could not be created.
EDIT: @Brian gave a better answer, which is more secure and robust in terms of race conditions.