is there a whitespace-free python convention?
Magnus Lie Hetland
mlh at furu.idi.ntnu.no
Mon Feb 10 13:22:27 EST 2003
In article <7ghebf5l2j.fsf at pikespeak.metacarta.com>, eichin at metacarta.com wrote:
[snip]
>So, working from both sides, is there a convention that people
>actually like for expressing indentation when it isn't really there?
Yes. See the script pindent.py in Tools/scripts in your Python
distribution. It basically closes every intented block with an "end"
comment. The script can be used both to add this sort of marking, and
to remove it -- and restore indentation if it has been destroyed.
This, according to the pindent convention,
def foobar(a, b):
if a == b:
a = a+1
elif a < b:
b = b-1
if b > a: a = a-1
# end if
else:
print 'oops!'
# end if
# end def foobar
is equivalent to
def foobar(a, b):
if a == b:
a = a+1
elif a < b:
b = b-1
if b > a: a = a-1
# end if
else:
print 'oops!'
# end if
# end def foobar
or even
def foobar(a, b):
if a == b:
a = a+1
elif a < b:
b = b-1
if b > a: a = a-1
else:
print 'oops!'
Since this script has been in the Python distro for years, it seems
like the most "standard" convention to adopt, IMO.
--
Magnus Lie Hetland "Nothing shocks me. I'm a scientist."
http://hetland.org -- Indiana Jones
More information about the Python-list
mailing list