New syntax for blocks
rt8396 at gmail.com
Wed Nov 11 09:08:58 CET 2009
On Nov 11, 1:25 am, Steven D'Aprano
<ste... at REMOVE.THIS.cybersource.com.au> wrote:
> >>> True == None
> >>> False == None
Of course i meant True/False but my fingers were thinking None at the
time. And besides if i don't make a mistake here or there what ever
would you do with your time? ;-)
Seven += 1
> > #variable "var" will never be created!
> That will cause no end of trouble.
> if range(N) as var:
> if var:
> print "Oops, this blows up if N <= 0"
> Conditional assignments are a terrible idea.
Yea it's called a NameError. Would it not also blow up in the current
state of syntax usage?
Traceback (most recent call last):
File "<pyshell#45>", line 1, in <module>
NameError: name 'var' is not defined
Steven -= 1
> Why is the third example, with an if... test, so special that it needs
> special syntax to make it a two-liner?
...because Beautiful is better than ugly.
> Would you suggest we can write this?
> # instead of var = range(N)
> p = range(N).index(5) as var # var might be range(N), or undefined.
No if you read my post my usage of this syntax only includes "if" and
"elif" constructs and nothing "else" because usage outside of such a
"truth-seeking" construct is pointless.
print Steven -> 0
Hmm, just as i suspected.
More information about the Python-list