<p>有时我发现我不得不在几行代码中使用长名称的函数,例如<code>os.path.abspath</code>和{<cd2>}a<strong>lot</strong>。我不认为在全局名称空间中使用这样的函数是不值得的,但是能够在我需要这些函数的行周围定义一个范围将是非常有用的。作为一个例子,这将是完美的:</p>
<pre><code>import os, sys
closure:
abspath = os.path.abspath
dirname = os.path.dirname
# 15 lines of heavy usage of those functions
# Can't access abspath or dirname here
</code></pre>
<p>我很想知道这是否可行</p>