def subst_vars(s, local_vars):
 check_environ()
 def _subst(match, local_vars=local_vars):
  var_name = match.group(1)
  if (var_name in local_vars):
   return str(local_vars[var_name])
  else:
   return os.environ[var_name]
 try:
  return re.sub('\\$([a-zA-Z_][a-zA-Z_0-9]*)', _subst, s)
 except KeyError as var:
  raise ValueError, ("invalid variable '$%s'" % var)

def subst_vars ( s , local_vars ) : check_environ ( ) def _subst ( match , local_vars = local_vars ) : var_name = match . group ( 1 ) if ( var_name in local_vars ) : return str ( local_vars [ var_name ] ) else : return os . environ [ var_name ] try : return re . sub ( '\\$([a-zA-Z_][a-zA-Z_0-9]*)' , _subst , s ) except KeyError as var : raise ValueError , ( "invalid variable '$%s'" % var )
perform shell/perl-style variable substitution on string .