Making safe file names
Terry Jan Reedy
tjreedy at udel.edu
Tue May 7 18:01:34 EDT 2013
On 5/7/2013 3:58 PM, Andrew Berg wrote:
> Currently, I keep Last.fm artist data caches to avoid unnecessary API calls and have been naming the files using the artist name. However,
> artist names can have characters that are not allowed in file names for most file systems (e.g., C/A/T has forward slashes). Are there any
> recommended strategies for naming such files while avoiding conflicts (I wouldn't want to run into problems for an artist named C-A-T or
> CAT, for example)? I'd like to make the files easily identifiable, and there really are no limits on what characters can be in an artist name.
Sounds like you want something like the html escape or urlencode
functions, which serve the same purpose of encoding special chars.
Rather than invent a new tranformation, you could use the same scheme
used for html entities. (Sorry, I forget the details.) It is possible
that one of the functions would work for you as is, or with little
modification.
Terry
More information about the Python-list
mailing list