[Tutor] A few comparative perl/python questions

alan.gauld@bt.com alan.gauld@bt.com
Mon, 29 Jul 2002 11:06:24 +0100


> > Does python have anything like Perl's || die, flock(), or seek()
> > functions?  (What are they?)

The previous answers have been appropriate but it occurs to me that a non
pythonic but literal translattion of Perl's

Foo() || die

idiom is possible in Python:

Foo() or raise SystemExit

The '||' is just Perl's logical OR and relies on 
short-circuit evaluation such that if the first 
value( Foo() )  is true we don't need to evaluate 
the second item. Pythons 'or' operator does the same. 

However although easy to translate it's not very 
Pythonic and I don't recommend it... 
Just noting the possibility.

Alan G.