本文整理匯總了Python中winreg.ExpandEnvironmentStrings方法的典型用法代碼示例。如果您正苦於以下問題:Python winreg.ExpandEnvironmentStrings方法的具體用法?Python winreg.ExpandEnvironmentStrings怎麽用?Python winreg.ExpandEnvironmentStrings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類winreg
的用法示例。
在下文中一共展示了winreg.ExpandEnvironmentStrings方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: expandvars
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ExpandEnvironmentStrings [as 別名]
def expandvars(var):
"""Expand environment variables.
Return the argument with environment variables expanded. Substrings of the
form $name or ${name} or %name% are replaced by the value of environment
variable name."""
if is_python2x() and isinstance(var, str):
final = var.decode('utf-8')
else:
final = var
if 'posix' == os.name:
final = os.path.expandvars(final)
elif 'nt' == os.name:
if sys.version_info[0] == 2:
import _winreg
else:
import winreg as _winreg
if final.startswith('${'):
final = re.sub(r'\$\{(.*?)\}(?=$|\\)',
lambda x: '%%%s%%' % x.group(1),
final)
elif final.startswith('$'):
final = re.sub(r'\$(.*?)(?=$|\\)',
lambda x: '%%%s%%' % x.group(1),
final)
final = _winreg.ExpandEnvironmentStrings(final)
return final
示例2: main
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ExpandEnvironmentStrings [as 別名]
def main():
paths, envpath = modify()
if len(paths) > 1:
print("Path(s) added:")
print('\n'.join(paths[1:]))
else:
print("No path was added")
print("\nPATH is now:\n%s\n" % envpath)
print("Expanded:")
print(winreg.ExpandEnvironmentStrings(envpath))