map/filter/reduce/lambda opinions and background unscientific mini-survey
Stian Søiland
stian at soiland.no
Wed Jul 6 15:08:22 EDT 2005
On 2005-07-06 16:33:47, Ron Adam wrote:
> *No more NamesError exceptions!
> print value
> >> None
So you could do lot's of funny things like:
def my_fun(extra_args=None):
if not extraargs:
print "Behave normally"
extra_args = 1337
if extraargs:
asdkjaskdj
..
if extra_args:
kajsdkasjd
and get no errors at all, but switching back and forth between the
different behavours because you actually did expect None, but from an
EXISTING variable.
> *No initialization needed for a while loop!
>
> while not something:
> if <condition>:
> something = True
This is the only "good" case I could find, but opening for a lots of
errors when you get used to that kind of coding:
while not finished:
foo()
finished = calculate_something()
(..)
(..) # Added another loop
while not finished:
bar()
finished = other_calculation()
Guess the amount of fun trying to find out the different errors that
could occur when bar() does not run as it should because the previous
"finished" variable changes the logic.
If you want to experiment with such designs, all you need to do is to
start your code with <?php
> *Test if name exists without using a try-except!
> if something == None:
> something = value
Now this is a question from newcomers on #python each day.. "How do I
check if a variable is set?".
Why do you want to check if a variable is set at all? If you have so
many places the variable could or could not be set, your program design
is basically flawed and must be refactored.
--
Stian Søiland Work toward win-win situation. Win-lose
Trondheim, Norway is where you win and the other lose.
http://soiland.no/ Lose-lose and lose-win are left as an
exercise to the reader. [Limoncelli/Hogan]
More information about the Python-list
mailing list