Archive for the Category: Python

Generate safe filenames using Python

This function removes illegal  characters to create file names that are safe to use on most operating systems. import string ## Make a file name that only contains safe charaters # @param inputFilename A filename containing illegal characters # @return A filename containing only safe characters def makeSafeFilename(inputFilename):     try:      safechars = string.letters + […]

Tagged , Leave a comment

Convert time in seconds to HH:MM:SS

## Convert time in seconds to hours:minutes:seconds # @param sec Time in seconds # @return The time in hh:mm:ss format def SecToTime(Sec): H = int(Sec / 3600) M = int(Sec / 60 – H * 60) S = int(Sec – (H * 3600 + M * 60)) if len(str(H)) == 1: time = “0” + […]

1 Comment