擅长:python、mysql、java
<p>你可以利用os.path.expandvars操作系统()(来自<a href="https://stackoverflow.com/questions/5258647/expanding-environment-variable-in-string-using-python">Expanding Environment variable in string using python</a>):</p>
<pre><code>import os
config_file = 'config.txt'
with open(config_file) as f:
for line in f:
temp_dir_name, ext = line.split('|')
dir_name = os.path.expandvars(temp_dir_name)
print dir_name
</code></pre>