Could somebody _PLEASE_ explain what's going on here?
Steve Juranich
sjuranic at condor.ee.washington.edu
Fri Nov 3 13:35:50 EST 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
following:
#
#
# This deals with accessing options that may have not been defined
# in the options file.
def __getattr__(self, k):
try:
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':
continue
strn = strn + k + " : "
if self.__dict__[k] == 1:
strn = strn + 'True\n'
elif self.__dict__[k] == 0:
strn = strn + 'False\n'
else:
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
sunos5
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 ee.washington.edu
Electrical Engineering http://students.washington.edu/sjuranic
University of Washington http://rcs.ee.washington.edu/ssli
More information about the Python-list
mailing list