Skip to content

Instantly share code, notes, and snippets.

@hidsh
Created December 6, 2011 03:16
Show Gist options
  • Save hidsh/1436542 to your computer and use it in GitHub Desktop.
Save hidsh/1436542 to your computer and use it in GitHub Desktop.
python: 変数の値をメンバ名として追加する
s = '^\\s*%s\\s*:\\s*(.+).*'
fields = ['vara', 'varb', 'varc', 'vard']
conf = t_config()
for ln in lines:
for f in fields:
m = re.match(s % f, ln, re.IGNORECASE)
if m:
conf.__dict__[f] = m.group(1) # e.g. conf.vara = '100'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment