Re: None

Jaap Vermeulen (jaap@sequent.com)
Fri, 10 Dec 93 13:52:00 PST

| I might think that 'ignore' is the name of the function to eat junk I
| want to skip! ( In fact, in this particular instance, that's just what
| I was doing: )

Actually, I once toyed with the idea to have every object return something,
itself by default (a la Smalltalk). Then you add an ignore() method to all
objects. This would result in being able to say

''.ignore()

to suppress the printing of the resulting value. This would come in
especially handy in situations where you want to do chaining of messages
(method), i.e.:

l = [8, 4, 5, 1, ...] # Consider this a passed in argument
for item in l.sort():
...

as where to ignore the result of sort() you would use:

l.sort.ignore()

Of course the chaining of messages doesn't make the code necessarily easier
to read, it just avoids unnecessary name bindings.

The above is not a serious proposal. The following is a serious proposal:

| try:
| here = file.tell( )
| except IOError:
| here = None

This reminds me of situations I sometimes (often enough) run into.

I have a try: statement that I like to keep short for the obvious reasons
but following it is code that should be executed only if the try succeeded.
The wrong way to do it is as follows:

try:
file = open('...', 'r')
data = process_file(file)
except IOError:
data = process_something_else()

Since the process_file could result in an IOError that I don't want to
catch.

Currently the only way to do that is:

try:
file = open('...', 'r')
readFile = 1
except IOError:
data = process_something_else()
readFile = 0

if readFile:
data = process_file(file)

My proposal is to add an 'else:' statement to the try:except: statement.
This statement would only be executed if the try: succeeded. This would be
consistent with the while:else: statement and for for:else: statement. The
code fragment would become:

try:
file = open('...', 'r')
except:
data = process_something_else()
else:
data = process_file(file)

What think?

-Jaap-