擅长:python、mysql、java
<p>因为在Python中,结束索引总是独占的,所以在内部始终使用“Python约定”值是值得考虑的。这样,您就可以避免在代码中混淆这两者。</p>
<p>仅通过专用转换子程序处理“外部表示”:</p>
<pre><code>def text2range(text):
m = re.match(r"from (\d+) to (\d+)",text)
start,end = int(m.groups(1)),int(m.groups(2))+1
def range2text(start,end):
print "from %d to %d"%(start,end-1)
</code></pre>
<p>或者,可以用<a href="http://www.joelonsoftware.com/articles/Wrong.html">true Hungarian notation</a>标记包含“异常”表示的变量。</p>