Something or Nothing^H^H^H^H^H^H^HEmpty

Philip Swartzleonard starx at pacbell.net
Wed Apr 10 05:11:38 EDT 2002


Anders J. Munch || Wed 10 Apr 2002 01:43:28a:

> Pythons truth values are not "Something or Nothing".  The phrase seems
> to have caught on following Laura's post, but I believe it is
> misleading.
> 
> [] and {} are objects, they are objects with identity, and they are
> mutable objects.  They are empty, but they are by no means "nothing".
> 
> Example:
> 
> def show(foo, history=None):
>     """prints foo, optionally storing what was printed in a history
>     list.""" print foo
>     if history:
>         history.append(foo)
> 
> This works as intended:
> 
>     # Omit default argument, don't remember history
>     show("hello world")
> 
> This works as intended:
> 
>     history = ["in the beginning was nothing"]
>     show("hello world", history) # adds "hello world" to history list
> 
> But this doesn't:
> 
>    history = []
>    show("hello world", history) # strange..history doesn't change
>    here? 
> 
> It doesn't work, because show() tests for emptyness with "if
> show_history:".  What show() should have done is test for nothingness
> using "if show_history is None:".

Hm, interesting. 

Right at this molment (and i'm a little tired), i'm thinking that None 
is only nothing by itself. Think of this, if we say:

x = None

x still exists. It isn't nothing. It's more like it's not here right 
now.*  We know what it is, we have a name for it, but we don't have any 
of it. We can test to see if it is there; if it dosen't exist, we can't 
test for it at all.

*This is sort of like how adventure games tend to handle nouns. If you 
say 'look at history', and history is in scope (in los/current area, not 
hidden, etc.), it will print something along the lines of 'history is a 
list. it contains a string.' (assuming we are in a text adventure that 
models the python interperter space as physical space... i'll have to 
try something like this sometime =). If there is a history somewhere, 
that is, that noun exists in the parser's dictonary_of_names, you'll get 
a message along the lines of "I don't see any history here.". However, 
if there is no such thing in the game world, and the parser dosen't know 
that word, it says "I don't know what a history is." (i.e. don't ever 
bother using the word again, it dosen't matter =).

ramble.Ramble.stop()

-- 
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com



More information about the Python-list mailing list