Could somebody _PLEASE_ explain what's going on here?

Steve Juranich sjuranic at
Fri Nov 3 19:35:50 CET 2000

Okay, I'm getting really frustrated here because I don't understand what's
going on.  Up to this morning, I had a class called "Table" that responded
very nicely to the "print" command.  Now, all of a sudden, it doesn't work. 

I have made a change in the code.  I overloaded the '__getattr__' to the

    # This deals with accessing options that may have not been defined
    # in the options file.
    def __getattr__(self, k):
            return self.__dict__[k]
        except KeyError:
            return None

and now here's my __repr__ function:

    # This is mainly used for debugging.
    def __repr__(self):
        strn = ''
        for k in self.__dict__.keys():
            if k == 'num_entries':
            strn = strn +  k + " : "
            if self.__dict__[k] == 1:
                strn = strn + 'True\n'
            elif self.__dict__[k] == 0:
                strn = strn + 'False\n'
                strn = strn + str(self.__dict__[k]) + '\n'

        # Get rid of the last carriage return (print adds one of its
        # own).
        if strn[-1] == '\n':
            strn = strn[:-1]
        return strn

The net result is I now get the following behavior:

Python 1.6 (#4, Sep 21 2000, 16:30:17)  [GCC 2.95.2 19991024 (release)] on
Copyright (c) 1995-2000 Corporation for National Research Initiatives.
All Rights Reserved.
Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved.
>>> import Table
>>> t = Table.Table('parfile.peaks')
>>> print t 

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: call of non-function (type None)
>>> print `t`
input_file_list : first_list
testing : True
output_dir : First
no_coda : True
use_energy : False
accent_constraint : none

As you can see, "print t" pukes, while "print `t`" works.  Why is this
broken now?  How do I fix it?

Thanks for the help.

Can't-think-of-a-pithy-sign-off-ly y'rs,

Stephen W. Juranich                         sjuranic at
Electrical Engineering
University of Washington   

More information about the Python-list mailing list