Skip to content

Instantly share code, notes, and snippets.

@ms8r
ms8r / yaml_ordered_dict.py
Created April 10, 2016 10:24 — forked from enaeseth/yaml_ordered_dict.py
Load YAML mappings as ordered dictionaries
import yaml
import yaml.constructor
try:
# included in standard lib from Python 2.7
from collections import OrderedDict
except ImportError:
# try importing the backported drop-in replacement
# it's available on PyPI
from ordereddict import OrderedDict
@ms8r
ms8r / sudo-relaunch.py
Created June 19, 2016 11:39
Python: Use sudo to re-launch a script as root
# This is how I ensure a Python script is launched as root, and automatically
# call 'sudo' to re-launch it as root if not.
# I found it useful to check the parameters are valid *before* re-launching as
# root, so I don’t have to enter the sudo password if there is a problem with
# the parameters, or I just want the help message.
import os
import sys