Skip to content

Instantly share code, notes, and snippets.

@mholgatem
Created January 11, 2016 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mholgatem/3ed3d6fe37b6643d43f2 to your computer and use it in GitHub Desktop.
Save mholgatem/3ed3d6fe37b6643d43f2 to your computer and use it in GitHub Desktop.
import re
file = '/home/pi/.advance/advmame.rc'
# search for '] keyboard[#,something]' or for 'scan0] or keyboard[#,something]'
pattern = re.compile("((?<=\]\s)|(?<=scan0\]\sor\s))keyboard\[\d,\w+\](?!\sor\skeyboard\[\d,\w+\])")
def keyboard_duplicate(matchobj):
return matchobj.group(0).replace('[1,', '[0,') + ' or ' + matchobj.group(0).replace('[0,', '[1,')
with open(file, 'r') as f:
data = f.read()
data = pattern.sub(keyboard_duplicate, data, re.IGNORECASE)
with open(file, 'w') as f:
f.write(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment