From: rantingrick on
I am pleased to announce optphart (alpha2)!

What is optphart?
optphart is the nemisis of the asinine interfaces and bulky libraries
you may be accustomed to in the stdlib. All of which clog your scripts
with wasted lines and your memory with complex interfaces far worse
than any colon clogging putrifaction of junk food can hold a candle
to. Do yourself a favor and give your scripts an enema by harnessing
the simplistic elegance of the "optphart" module instead!

Whats new in this release:
- This release is less likely to blow chunks than the last.
- Now you can pass single opts! Woo Hoo!

def optphart(args):
d = {'args':[], 'opts':[]}
for arg in args:
if arg.startswith('-'):
key, value = arg.split('=', 1)
except ValueError:
options = value.split(',')
if len(options) > 1:
d[key[1:]] = filter(None, options)
d[key[1:]] = value
return d

if __name__ == '__main__':
args = [
'-key2=value2,', #trailing comma converts to array
opts = optphart(args)
#print opts.keys()
for k,v in opts.items():
print '%s -> %s' %(k, v)