Why does list have no 'get' method?

P

pruebauno

Ok, the fix is easy:

val = BETTER foo THAN bar

;-)

Cobol-strikes-back-ly yours,

George

I use a ETL language/tool that actually has a function for this kind
of thing:

NulltoValue(value,defaultValue)

it returns defaultValue if value is null otherwise value.
 
C

Carl Banks

Can't you just make a subclass of Boolean and add methods to the true/
false, or am i running up a tree with a cat?

I'm not sure what point you were trying to make, but no you can't
subclass bool in Python as it is now; certainly it wouldn't be
possible if Python treated bools according to my preference.

Carl Banks
 
G

Gabriel Genellina

Matt.
(would it help if I put lots of blank lines after this, so the disclaimer
is out-of-sight/out-of-mind?)

No, what would help is a line containing *exactly*
(dash)(dash)(space)(newline)
That is, add a single space after those two dashes above.
 
B

bearophileHUGS

Carl Banks:
I think booleans should be completely disjoint from all other types,
as they are in Java. "and", "or", and "not" should accept only boolean
operands and return only boolean results.

I'd like "or" and "and" (and "not") to return booleans only, to avoid
bugs and make their meaning more transparent, but I like the fact that
empty containers like "" [] (,) {} are seen as false:

x = []
if x:
...
else:
... // goes here

bool([]) ==> False

So I don't mind "and", "or" to take non-booleans too as input:

[] or "aa" ==> True

I think that's a good compromise between practicality, and avoiding
bugs.

"not" already works that way, it takes other objects too as input, but
its output is always a bool:
True

Bye,
bearophile
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,226
Latest member
KristanTal

Latest Threads

Top