diff --git a/utils.py b/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..696c80dae818a2d6596464700e2233e35df486aa --- /dev/null +++ b/utils.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Utility functions + +Karl Hoffmann, Max Planck Institute of Molecular Cell Biology and Genetics, +Dresden, Germany +""" + +def str_filename(number, *args, **kwargs): + """ + Conversion of a number (or any other object) to a string that is compatible + with file name syntax. + Based on the built-in function str(), but replaces some characters that + have special meaning in filenames: + File extension separator '.' and path separators (both slash and backslash) + are each replaced with underscore '_' + """ + return str(number,*args,**kwargs).translate(str.maketrans({'.' : '_', + '/' : '_', + '\\' : '_' #note the escape to describe a single backslash + })) \ No newline at end of file