Archives for posts tagged ‘Python’

Python: Search & Find & Move a File

I need to find a file that is hidden somewhere in a directory tree. So I search for it recursively. On UNIX the “find” command works just fine for this, but I wanted a Python native solution and finally came up with both:
import os

def findFile(name, directory):
“”"
[...]

Python: Parse mixed ranges and lists

I have to create a list of numbers from a string in a configuration file that looks about like this:
132,120-130,135,139
Since users sometimes add blanks in configurations files just to make them look nicer this should also work with a string like this:
132, 120 – 130 , 135,139
The resulting list should be sorted and contain only [...]

Python: Process already running?

I use the application name and “ps” to find the process’ pid (all of them if there are more processes called name). If no pid is found there no instance of the application running.
import os

def getpid(name):
“”"
checks if a process with the given name [...]