Learing Python, Newbie question

Steve Holden sholden at holdenweb.com
Thu Oct 25 13:12:51 CEST 2001


"Johannes Gamperl" <info at devshare.de> wrote ...
> michael at rcp.co.uk says...
> > Johannes Gamperl <info at devshare.de> wrote:
> >
> > > Do you know if there is a
> > > coditional operator in python ( ?: )
> > >
> > > e.g.
> > >
> > > if os.path.exists("gbook.txt"):
> > >   db_first = 0;
> > > else:
> > >   db_first = 1;
> > >
> > >
> > > db_first = ( os.path.exists("gbook.txt") ) ? 0:1;
> >
> > Ho ho!
> >
> > I'm glad that beginners also miss the conditional operator.
> >
> > I'm afraid there's been a bit of an argument about possible syntax, and
> > most of the old hands seem firmly convinced that the conditional
operator
> > serves no useful purpose.
> >
> > No, it doesn't exist!
> >
> >
> > Mind you, in the example you give, there's no point at all in having a
> > conditional operator, since what you *really* wanted to write is:
> >
> >     db_first = not os.path.exists("gbook.txt")
>
> hello Michael,
>
> the e.g. doesn't make sin :) .. but i want to describe for what i'm
> looking for. i came from perl and i find the conditional operator very
> usefull ..
>
> oki ... my journey to python goes on ;)
>
Not, you understand, that there's any *prejudice* against a conditional
operator. There has been a lot of discussion as to how the equivalent to the
C/Perl operator could/should be programmed in Python as it currently exists,
and also some (!) discussion as to how a new feature could be added to the
language.

What we are currently missing is *agreement* - both on whether it's really
useful and, more especially, on what the syntax should be.

Keep asking questions!

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list