Pythonic way to manage hosts file