擅长:python、mysql、java
<p><code>os.path.relpath()</code>假设其参数是目录。</p>
<pre><code>>>> os.path.join(os.path.relpath(os.path.dirname('foo/bar/bar_file.txt'),
os.path.dirname('foo/foo_file.txt')),
os.path.basename('foo/bar/bar_file.txt'))
'bar/bar_file.txt'
</code></pre>