4 ms·
> Territorial Dispute def path_normalize(path): try: path = re.sub('%(.+)%', (lambda m: ('%{0}%'.format(m.group(1)) if (m.group(1) not in dat
by oefrha 7y ago
> Territorial Dispute
def path_normalize(path):
try:
path = re.sub('%(.+)%', (lambda m: ('%{0}%'.format(m.group(1)) if (m.group(1) not in datastore.ENV_VARS) else datastore.ENV_VARS[m.group(1)])), path)
except:
tedilog.error(...)
return path
What a terrible way to write
return re.sub(r'%(.+)%', lambda m: datastore.ENV_VARS.get(m.group(1), m.group(0)), path)
- deleted 7y ago[deleted]
- itsspring 7y agoDoes yours catch the exception?
- oefrha 7y agoApparently I didn’t include the parts that don’t need to be changed. (Actually, with the correct input type, this piece of code shouldn’t raise any exception period other than BaseExcept like KeyboardInterrupt, which usually shouldn’t be caught like this either. So I would omit the try...except myself.)
- mimimi31 7y agoAlso: if result: return True return False