Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79415 > unrolled thread

(test) ? a:b

Started by"ast" <nomail@invalid.com>
First post2014-10-22 10:29 +0200
Last post2014-10-24 11:31 -0700
Articles 20 on this page of 77 — 23 participants

Back to article view | Back to comp.lang.python


Contents

  (test) ? a:b "ast" <nomail@invalid.com> - 2014-10-22 10:29 +0200
    Re: (test) ? a:b buscacio@gmail.com - 2014-10-22 02:05 -0700
      Re: (test) ? a:b "ast" <nomail@invalid.com> - 2014-10-22 11:14 +0200
        Re: (test) ? a:b Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-22 12:45 +0100
          Re: (test) ? a:b "ast" <nomail@invalid.com> - 2014-10-27 09:01 +0100
        Re: (test) ? a:b Michael Torrie <torriem@gmail.com> - 2014-10-22 11:16 -0600
          Re: (test) ? a:b Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-23 11:44 +1100
      Re: (test) ? a:b Chris Angelico <rosuav@gmail.com> - 2014-10-22 20:15 +1100
      Re: (test) ? a:b Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-22 10:16 +0100
      Re: (test) ? a:b Chris Angelico <rosuav@gmail.com> - 2014-10-22 20:27 +1100
        Re: (test) ? a:b Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-10-23 16:46 +1300
          Re: (test) ? a:b MRAB <python@mrabarnett.plus.com> - 2014-10-23 11:12 +0100
            Re: (test) ? a:b "ast" <nomail@invalid.com> - 2014-10-24 08:38 +0200
          Re: (test) ? a:b Michael Torrie <torriem@gmail.com> - 2014-10-25 19:04 -0600
            Re: (test) ? a:b Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-10-27 22:04 +1300
          Re: (test) ? a:b Chris Angelico <rosuav@gmail.com> - 2014-10-26 12:20 +1100
          Re: (test) ? a:b Michael Torrie <torriem@gmail.com> - 2014-10-25 21:05 -0600
      Re: (test) ? a:b Ned Batchelder <ned@nedbatchelder.com> - 2014-10-22 07:30 -0400
        Re: (test) ? a:b Marko Rauhamaa <marko@pacujo.net> - 2014-10-22 14:41 +0300
        Re: (test) ? a:b Rustom Mody <rustompmody@gmail.com> - 2014-10-22 06:16 -0700
          Re: (test) ? a:b "BartC" <bc@freeuk.com> - 2014-10-22 19:08 +0100
            Re: (test) ? a:b Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-22 19:55 -0400
              Re: (test) ? a:b "BartC" <bc@freeuk.com> - 2014-10-23 11:50 +0100
                Re: (test) ? a:b Marko Rauhamaa <marko@pacujo.net> - 2014-10-23 16:44 +0300
                  Re: (test) ? a:b Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-23 08:24 -0600
                  Re: (test) ? a:b Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2014-10-23 16:41 +0200
                    Re: (test) ? a:b Marko Rauhamaa <marko@pacujo.net> - 2014-10-23 19:20 +0300
                  Re: (test) ? a:b Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-24 19:38 +1100
                    Re: (test) ? a:b Chris Angelico <rosuav@gmail.com> - 2014-10-24 19:45 +1100
                    Re: (test) ? a:b Marko Rauhamaa <marko@pacujo.net> - 2014-10-24 12:37 +0300
                      Re: (test) ? a:b Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-25 00:07 +1100
                        Re: (test) ? a:b Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-24 12:22 -0600
                          Re: (test) ? a:b Marko Rauhamaa <marko@pacujo.net> - 2014-10-24 21:46 +0300
                    Re: (test) ? a:b Dan Stromberg <drsalists@gmail.com> - 2014-10-24 10:20 -0700
                      Re: (test) ? a:b alister <alister.nospam.ware@ntlworld.com> - 2014-10-24 20:58 +0000
                        Re: (test) ? a:b Marko Rauhamaa <marko@pacujo.net> - 2014-10-25 00:02 +0300
                        Re: (test) ? a:b Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-25 16:03 +1100
                          Re: (test) ? a:b Chris Angelico <rosuav@gmail.com> - 2014-10-25 16:25 +1100
                          Re: (test) ? a:b Ned Batchelder <ned@nedbatchelder.com> - 2014-10-25 07:58 -0400
                          Re: (test) ? a:b Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-25 07:53 -0600
                          Re: (test) ? a:b Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-25 14:11 -0400
                          Re: (test) ? a:b alister <alister.nospam.ware@ntlworld.com> - 2014-10-25 19:49 +0000
                          Re: (test) ? a:b Ben Finney <ben+python@benfinney.id.au> - 2014-10-26 07:45 +1100
                            Re: (test) ? a:b Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-26 11:10 +1100
                              Re: (test) ? a:b Ben Finney <ben+python@benfinney.id.au> - 2014-10-26 12:03 +1100
                                Re: (test) ? a:b Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-26 15:15 +1100
                                  Re: (test) ? a:b Chris Angelico <rosuav@gmail.com> - 2014-10-26 15:34 +1100
                                  Re: (test) ? a:b Terry Reedy <tjreedy@udel.edu> - 2014-10-26 17:12 -0400
                                  Re: (test) ? a:b Ben Finney <ben+python@benfinney.id.au> - 2014-10-27 11:38 +1100
                                  Re: (test) ? a:b MRAB <python@mrabarnett.plus.com> - 2014-10-27 01:40 +0000
                                  Re: (test) ? a:b Rustom Mody <rustompmody@gmail.com> - 2014-10-26 19:19 -0700
                              Re: (test) ? a:b Ben Finney <ben+python@benfinney.id.au> - 2014-10-26 12:10 +1100
                              Re: (test) ? a:b Joshua Landau <joshua@landau.ws> - 2014-10-27 01:55 +0000
                              Re: (test) ? a:b Ben Finney <ben+python@benfinney.id.au> - 2014-10-27 13:28 +1100
                                Re: (test) ? a:b Rustom Mody <rustompmody@gmail.com> - 2014-10-26 19:38 -0700
                              Re: (test) ? a:b Joshua Landau <joshua@landau.ws> - 2014-10-27 02:43 +0000
                              Re: (test) ? a:b Ben Finney <ben+python@benfinney.id.au> - 2014-10-27 13:56 +1100
                          Re: (test) ? a:b Dan Stromberg <drsalists@gmail.com> - 2014-10-25 15:34 -0700
                          Re: (test) ? a:b Ben Finney <ben+python@benfinney.id.au> - 2014-10-26 10:53 +1100
                          Re: (test) ? a:b Chris Angelico <rosuav@gmail.com> - 2014-10-26 11:01 +1100
                          Re: (test) ? a:b Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-26 01:09 +0100
                          Re: (test) ? a:b Chris Angelico <rosuav@gmail.com> - 2014-10-26 11:13 +1100
            Re: (test) ? a:b Vito De Tullio <vito.detullio@gmail.com> - 2014-10-23 06:55 +0200
        Re: (test) ? a:b Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-23 03:28 +1100
          Re: (test) ? a:b Chris Angelico <rosuav@gmail.com> - 2014-10-23 03:40 +1100
          Re: (test) ? a:b alister <alister.nospam.ware@ntlworld.com> - 2014-10-22 18:03 +0000
          Re: (test) ? a:b Matthew Ruffalo <mmr15@case.edu> - 2014-10-22 14:27 -0400
          Re: (test) ? a:b Chris Angelico <rosuav@gmail.com> - 2014-10-23 05:30 +1100
          Re: (test) ? a:b Ned Batchelder <ned@nedbatchelder.com> - 2014-10-22 16:11 -0400
      Re: (test) ? a:b Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-22 12:41 +0100
        Re: (test) ? a:b alister <alister.nospam.ware@ntlworld.com> - 2014-10-22 15:12 +0000
          Re: (test) ? a:b Chris Angelico <rosuav@gmail.com> - 2014-10-23 02:18 +1100
            Re: (test) ? a:b alister <alister.nospam.ware@ntlworld.com> - 2014-10-22 15:24 +0000
      Re: (test) ? a:b Dan Stromberg <drsalists@gmail.com> - 2014-10-22 09:09 -0700
    Re: (test) ? a:b Tobiah <toby@tobiah.org> - 2014-10-24 10:23 -0700
      Re: (test) ? a:b Chris Angelico <rosuav@gmail.com> - 2014-10-25 04:27 +1100
        Re: (test) ? a:b Tobiah <toby@tobiah.org> - 2014-10-24 11:31 -0700

Page 1 of 4  [1] 2 3 4  Next page →


#79415 — (test) ? a:b

From"ast" <nomail@invalid.com>
Date2014-10-22 10:29 +0200
Subject(test) ? a:b
Message-ID<54476af8$0$21651$426a74cc@news.free.fr>
Hello

Is there in Python something like:

j = (j >= 10) ? 3 : j+1;

as in C language ?

thx

[toc] | [next] | [standalone]


#79419

Frombuscacio@gmail.com
Date2014-10-22 02:05 -0700
Message-ID<7839376e-fc27-4299-ae63-4ddf17ef9a8a@googlegroups.com>
In reply to#79415
Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast  escreveu:
> Hello
> 
> 
> 
> Is there in Python something like:
> 
> 
> 
> j = (j >= 10) ? 3 : j+1;
> 
> 
> 
> as in C language ?
> 
> 
> 
> thx

without not:
j = [j+1, 3][j>=10]
with not:
j = [3, j+1][not (j>=10)]

[toc] | [prev] | [next] | [standalone]


#79421

From"ast" <nomail@invalid.com>
Date2014-10-22 11:14 +0200
Message-ID<544775ca$0$2146$426a74cc@news.free.fr>
In reply to#79419
<buscacio@gmail.com> a écrit dans le message de 
news:7839376e-fc27-4299-ae63-4ddf17ef9a8a@googlegroups.com...
> Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast  escreveu:
>> Hello
>>
>>
>>
>> Is there in Python something like:
>>
>>
>>
>> j = (j >= 10) ? 3 : j+1;
>>
>>
>>
>> as in C language ?
>>
>>
>>
>> thx
>
> without not:
> j = [j+1, 3][j>=10]
> with not:
> j = [3, j+1][not (j>=10)]
>

Oh it's a trick !
thx 

[toc] | [prev] | [next] | [standalone]


#79437

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-10-22 12:45 +0100
Message-ID<mailman.15070.1413978605.18130.python-list@python.org>
In reply to#79421
On 22/10/2014 10:14, ast wrote:
>
> <buscacio@gmail.com> a écrit dans le message de
> news:7839376e-fc27-4299-ae63-4ddf17ef9a8a@googlegroups.com...
>> Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast  escreveu:
>>> Hello
>>>
>>>
>>>
>>> Is there in Python something like:
>>>
>>>
>>>
>>> j = (j >= 10) ? 3 : j+1;
>>>
>>>
>>>
>>> as in C language ?
>>>
>>>
>>>
>>> thx
>>
>> without not:
>> j = [j+1, 3][j>=10]
>> with not:
>> j = [3, j+1][not (j>=10)]
>>
>
> Oh it's a trick !
> thx

IMHO it's just dreadful.  Why people insist on messing around like this 
I really don't know, it just drives me nuts.

Also would you please access this list via 
https://mail.python.org/mailman/listinfo/python-list or read and action 
this https://wiki.python.org/moin/GoogleGroupsPython to prevent us 
seeing double line spacing and single line paragraphs, thanks.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#79769

From"ast" <nomail@invalid.com>
Date2014-10-27 09:01 +0100
Message-ID<544dfbdf$0$2148$426a74cc@news.free.fr>
In reply to#79437
"Mark Lawrence" <breamoreboy@yahoo.co.uk> a écrit dans le message de 
news:mailman.15070.1413978605.18130.python-list@python.org...

> Also would you please access this list via https://mail.python.org/mailman/listinfo/python-list or 
> read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double 
> line spacing and single line paragraphs, thanks.

Hi

I read the last document but it seems that it is intended for those who
post messages through Google Groups. I am using a usenet client so i
should not be affected

It seems that he double blank lines spacing comes from buscacio, not me

regards 

[toc] | [prev] | [next] | [standalone]


#79462

FromMichael Torrie <torriem@gmail.com>
Date2014-10-22 11:16 -0600
Message-ID<mailman.15087.1413999869.18130.python-list@python.org>
In reply to#79421
On 10/22/2014 05:45 AM, Mark Lawrence wrote:
>>> without not:
>>> j = [j+1, 3][j>=10]
>>> with not:
>>> j = [3, j+1][not (j>=10)]
>>>
>>
>> Oh it's a trick !
>> thx
> 
> IMHO it's just dreadful.  Why people insist on messing around like this 
> I really don't know, it just drives me nuts.

This actually was the standard idiom used by many python programs before
Python 2.5.  But I agree.  Don't do this anymore! Python has a ternary
if expression. Also the ternary if expression does, I believe
short-circuit logic, so the non-chosen path is not calculated.  This
hack does not. Could lead to interesting bugs depending on your assumptions.

[toc] | [prev] | [next] | [standalone]


#79490

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-10-23 11:44 +1100
Message-ID<54484f66$0$13011$c3e8da3$5496439d@news.astraweb.com>
In reply to#79462
Michael Torrie wrote:

> On 10/22/2014 05:45 AM, Mark Lawrence wrote:
>>>> without not:
>>>> j = [j+1, 3][j>=10]
>>>> with not:
>>>> j = [3, j+1][not (j>=10)]
>>>>
>>>
>>> Oh it's a trick !
>>> thx
>> 
>> IMHO it's just dreadful.  Why people insist on messing around like this
>> I really don't know, it just drives me nuts.
> 
> This actually was the standard idiom used by many python programs before
> Python 2.5.  But I agree.  Don't do this anymore! Python has a ternary
> if expression. Also the ternary if expression does, I believe
> short-circuit logic, so the non-chosen path is not calculated.  This
> hack does not. Could lead to interesting bugs depending on your
> assumptions.

Working code doesn't suddenly become non-working code just because Python
adds a second way to do something. The standard idiom

    (value_if_false, value_if_true)[condition]

worked from (at least) Python 1.5 to Python 2.4, and it continues to work
today. There's nothing wrong with it: it does what it does, nothing more,
nothing less, and the only hashish part of this is that bools *are* ints,
with True == 1 and False == 0. That was heavily debated back in 2.3 or
thereabouts when bools were first introduced, and the decision made then
wasn't reverted in Python 3, so you can take it as By Design and not a
fluke of history. I think it is fair to say that Guido likes it that bools
are ints.

The older idiom isn't *exactly* the same as the ternary if operator, since
that short-circuits, but for many purposes short-circuiting is not
important or needed. If you don't need short-circuiting, or you dislike the
order of `value_if_true if condition else value_if_false`, or you need to
support Python 2.4 or older, or *simply because you like it*, there is
nothing wrong with using the older `sequence[flag]` idiom.

(It amuses me that not that many years ago the general attitude here was
that ternary if was an abomination that no right-thinking person should
ever use because the order of terms isn't identical to C, and now the
attitude seems to be that anyone *not* using ternary if is a heretic who
deserves to be set on fire :-)



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#79422

FromChris Angelico <rosuav@gmail.com>
Date2014-10-22 20:15 +1100
Message-ID<mailman.15060.1413969362.18130.python-list@python.org>
In reply to#79419
On Wed, Oct 22, 2014 at 8:05 PM,  <buscacio@gmail.com> wrote:
> Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast  escreveu:
>> Hello
>>
>>
>>
>> Is there in Python something like:
>>
>>
>>
>> j = (j >= 10) ? 3 : j+1;
>>
>>
>>
>> as in C language ?
>>
>>
>>
>> thx
>
> without not:
> j = [j+1, 3][j>=10]
> with not:
> j = [3, j+1][not (j>=10)]

There's a distinct semantic difference there, though. Compare these:

/* C */
int x = (y != 0) ? 65536/y : 0;

# Python
x = 65536/y if y else 0

# Python, your way
x = [0, 65536/y][y!=0]

Do you see where the problem is?

Plus, subscripting a literal list is far less readable than the
ternary operator.

Also: Please can you avoid Google Groups, or if you must use it,
please at least clean up the excessive blank lines before you post.
I've left them so you can see what we have to cope with. Thanks!

ChrisA

[toc] | [prev] | [next] | [standalone]


#79423

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-10-22 10:16 +0100
Message-ID<mailman.15061.1413969382.18130.python-list@python.org>
In reply to#79419
On 22/10/2014 10:05, buscacio@gmail.com wrote:
> Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast  escreveu:
>> Hello
>>
>>
>>
>> Is there in Python something like:
>>
>>
>>
>> j = (j >= 10) ? 3 : j+1;
>>
>>
>>
>> as in C language ?
>>
>>
>>
>> thx
>
> without not:
> j = [j+1, 3][j>=10]
> with not:
> j = [3, j+1][not (j>=10)]
>

The death penalty should be reintroduced into the UK for two crimes, 
writing code like the above and using google groups.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#79425

FromChris Angelico <rosuav@gmail.com>
Date2014-10-22 20:27 +1100
Message-ID<mailman.15062.1413971583.18130.python-list@python.org>
In reply to#79419
On Wed, Oct 22, 2014 at 8:16 PM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
>> without not:
>> j = [j+1, 3][j>=10]
>> with not:
>> j = [3, j+1][not (j>=10)]
>>
>
> The death penalty should be reintroduced into the UK for two crimes, writing
> code like the above and using google groups.

No no no. Code like that doesn't deserve death, just community
service. I've seen much MUCH worse... where multiple conditional
expressions get combined arithmetically, and then the result used
somewhere... I also may have been guilty of same, myself, though I'm
going to plead the internet's equivalent of the Fifth Amendment to the
US Constitution and not incriminate myself by showing the code...

ChrisA

[toc] | [prev] | [next] | [standalone]


#79500

FromGregory Ewing <greg.ewing@canterbury.ac.nz>
Date2014-10-23 16:46 +1300
Message-ID<carc00FdrboU1@mid.individual.net>
In reply to#79425
Chris Angelico wrote:
> I've seen much MUCH worse... where multiple conditional
> expressions get combined arithmetically, and then the result used
> somewhere...

In the days of old-school BASIC it was common to
exploit the fact that boolean expressions evaluated
to 0 or 1 (or -1, depending on your dialect :) to
achieve conditional expressions or other tricks.

Probably forgiveable, given that there were no real
conditional expressions, and every byte of your 48K
or less of RAM was precious...

-- 
Greg

[toc] | [prev] | [next] | [standalone]


#79509

FromMRAB <python@mrabarnett.plus.com>
Date2014-10-23 11:12 +0100
Message-ID<mailman.15107.1414059182.18130.python-list@python.org>
In reply to#79500
On 2014-10-23 04:46, Gregory Ewing wrote:
> Chris Angelico wrote:
>> I've seen much MUCH worse... where multiple conditional
>> expressions get combined arithmetically, and then the result used
>> somewhere...
>
> In the days of old-school BASIC it was common to
> exploit the fact that boolean expressions evaluated
> to 0 or 1 (or -1, depending on your dialect :) to
> achieve conditional expressions or other tricks.
>
> Probably forgiveable, given that there were no real
> conditional expressions, and every byte of your 48K
> or less of RAM was precious...
>
48K? Luxury!

[toc] | [prev] | [next] | [standalone]


#79558

From"ast" <nomail@invalid.com>
Date2014-10-24 08:38 +0200
Message-ID<5449f3d7$0$2061$426a74cc@news.free.fr>
In reply to#79509
> 48K? Luxury!

ZX81 had an option for 64K

[toc] | [prev] | [next] | [standalone]


#79698

FromMichael Torrie <torriem@gmail.com>
Date2014-10-25 19:04 -0600
Message-ID<mailman.15184.1414285521.18130.python-list@python.org>
In reply to#79500
On 10/22/2014 09:46 PM, Gregory Ewing wrote:
> Chris Angelico wrote:
>> I've seen much MUCH worse... where multiple conditional
>> expressions get combined arithmetically, and then the result used
>> somewhere...
> 
> In the days of old-school BASIC it was common to
> exploit the fact that boolean expressions evaluated
> to 0 or 1 (or -1, depending on your dialect :) to
> achieve conditional expressions or other tricks.

As far as I can tell, no BASIC dialect I've looked at (DOS and Linux
worlds only), has ever had any logical operators like AND (&&), OR (||),
and NOT (!).  They only appear to have bitwise operators (&,|,~ C
equivalent).  The fact that comparison operators returned 0 and -1 made
the bitwise operators function the same as logical.  But you can run
into trouble if you tried to use a common python idiom like this:

x = read_some_lines() 'returns number of lines read, or zero if none are
if not x:
	print ("I couldn't read any lines")
	exit(1)

Basically any value other than -1 for x would cause the not x to be
true.  Off topic, and no matter to python programmers.  But for BASIC
you need to watch out for this.  One BASIC dialect introduced a set of
functions, istrue() and isfalse() to convert a non-zero truth value to
-1, and any falsish value to zero (like maybe an empty string).  That
way the bitwise operators would always function as logical operators in
a conditional expression.

[toc] | [prev] | [next] | [standalone]


#79773

FromGregory Ewing <greg.ewing@canterbury.ac.nz>
Date2014-10-27 22:04 +1300
Message-ID<cb6g43F9ppvU1@mid.individual.net>
In reply to#79698
Michael Torrie wrote:
> As far as I can tell, no BASIC dialect I've looked at (DOS and Linux
> worlds only), has ever had any logical operators like AND (&&), OR (||),
> and NOT (!).  They only appear to have bitwise operators (&,|,~ C
> equivalent).  The fact that comparison operators returned 0 and -1 made
> the bitwise operators function the same as logical.

Applesoft used 0 and 1, so its NOT definitely wasn't bitwise
on the whole number. I can't remember what its AND and OR did
for numbers other than 0 or 1 (if I even thought to try it),
but since it did all arithmetic in floating point, I suspect
they were logical rather than bitwise.

-- 
Greg

[toc] | [prev] | [next] | [standalone]


#79700

FromChris Angelico <rosuav@gmail.com>
Date2014-10-26 12:20 +1100
Message-ID<mailman.15186.1414286413.18130.python-list@python.org>
In reply to#79500
On Sun, Oct 26, 2014 at 12:04 PM, Michael Torrie <torriem@gmail.com> wrote:
> But you can run
> into trouble if you tried to use a common python idiom like this:
>
> x = read_some_lines() 'returns number of lines read, or zero if none are
> if not x:
>         print ("I couldn't read any lines")
>         exit(1)
>
> Basically any value other than -1 for x would cause the not x to be
> true.

So don't use Python idioms in BASIC. :) Back when I used to write
BASIC code, I'd do explicit comparisons with zero for this sort of
thing... these days, I'd use Python idioms, but I'd also write Python
code :)

I think it's indicative that the BASIC code I'm most proud of was
consciously getting around language limitations (I wrote a mess of
code in assembly language and Q-BASIC to allow my programs to use the
mouse), but the Python code I'm most proud of is using the language's
strengths.

ChrisA

[toc] | [prev] | [next] | [standalone]


#79701

FromMichael Torrie <torriem@gmail.com>
Date2014-10-25 21:05 -0600
Message-ID<mailman.15187.1414292754.18130.python-list@python.org>
In reply to#79500
On 10/25/2014 07:20 PM, Chris Angelico wrote:
> So don't use Python idioms in BASIC. :) Back when I used to write
> BASIC code, I'd do explicit comparisons with zero for this sort of
> thing... these days, I'd use Python idioms, but I'd also write Python
> code :)
> 
> I think it's indicative that the BASIC code I'm most proud of was
> consciously getting around language limitations (I wrote a mess of
> code in assembly language and Q-BASIC to allow my programs to use the
> mouse), but the Python code I'm most proud of is using the language's
> strengths.

Hey I did the same thing in Turbo and then later Power BASIC.

I have a soft spot for BASIC, and now with FreeBASIC releasing their 1.0
release (object-oriented capabilities and the works), I revisited a bit
of my BASIC past.  Translated a few programs from Turbo and Power BASIC
into the more modern FreeBASIC dialect.  But now that that's done, it's
back to Python, where I'm going to stay!  Python reminds me of the best
BASIC had to offer plus a whole lot more.

[toc] | [prev] | [next] | [standalone]


#79432

FromNed Batchelder <ned@nedbatchelder.com>
Date2014-10-22 07:30 -0400
Message-ID<mailman.15068.1413977455.18130.python-list@python.org>
In reply to#79419
On 10/22/14 5:05 AM, buscacio@gmail.com wrote:
> Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast  escreveu:
>> Hello
>>
>>
>>
>> Is there in Python something like:
>>
>>
>>
>> j = (j >= 10) ? 3 : j+1;
>>
>>
>>
>> as in C language ?
>>
>>
>>
>> thx
>
> without not:
> j = [j+1, 3][j>=10]
> with not:
> j = [3, j+1][not (j>=10)]
>

Why on earth would you recommend this outdated hack, when there's a true 
conditional operator?

     j = 3 if j >= 10 else j+1

Of course, many people feel like the conditional operator isn't worth 
the squished-up unreadability, but if someone asks for a conditional 
operator, at least show them one!

-- 
Ned Batchelder, http://nedbatchelder.com

[toc] | [prev] | [next] | [standalone]


#79435

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-10-22 14:41 +0300
Message-ID<87siigwcu1.fsf@elektro.pacujo.net>
In reply to#79432
Ned Batchelder <ned@nedbatchelder.com>:

> Why on earth would you recommend this outdated hack, when there's a
> true conditional operator? [...] if someone asks for a conditional
> operator, at least show them one!

No good deed goes unpunished.


Marko

[toc] | [prev] | [next] | [standalone]


#79441

FromRustom Mody <rustompmody@gmail.com>
Date2014-10-22 06:16 -0700
Message-ID<7d2ea3c1-504e-4f5c-8338-501b1483df38@googlegroups.com>
In reply to#79432
On Wednesday, October 22, 2014 5:01:08 PM UTC+5:30, Ned Batchelder wrote:
> On 10/22/14 5:05 AM, buscacio wrote:
> > Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast  escreveu:
> >> Hello
> >> Is there in Python something like:
> >> j = (j >= 10) ? 3 : j+1;
> >> as in C language ?
> >> thx
> > without not:
> > j = [j+1, 3][j>=10]
> > with not:
> > j = [3, j+1][not (j>=10)]

> Why on earth would you recommend this outdated hack, when there's a true 
> conditional operator?


To learn a bit about the interchangeability of control and data structures?

[Just playing devil's advocate]

Doesn't change the fact that as a practice it should not be done

[toc] | [prev] | [next] | [standalone]


Page 1 of 4  [1] 2 3 4  Next page →

Back to top | Article view | comp.lang.python


csiph-web