[Tutor] Need Help with Source Code

Guillermo Fernandez Castellanos guillermo.fernandez at epfl.ch
Wed Aug 18 07:28:42 CEST 2004


Hi,

 > could someone take the attachments and run the source code in python
 > and see
 > where I made the mistakes.  I am trying to get the source code into an
 > telephone database using python.

I runned your code, and tryed to insert a new user on your database:
C:\Documents and Settings\Administrator\Desktop>python test3.py
If you want to add an Employee type the #: 1
For a complete listing of Employees type the #: 2
To see the 'test page' and exit the Database type the #: 3
:1
Enter the Employee's full name:
:guille
Enter the Employee's full telephone number:
:00210410343
Enter the telephone number type: (0 = UNKNOWN, 1 = HOME, 2 = WORK, 3 = 
FAX, 4 =
CELL)
:1

Here comes what interest us:
Traceback (most recent call last):
   File "test3.py", line 33, in ?
     foo.add(n, p, "HOME")
   File "C:\Documents and Settings\Administrator\Desktop\phone.py", line 
52, in a
dd
     self.shelve[str(e)] = e
   File "C:\Documents and Settings\Administrator\Desktop\phone.py", line 
23, in _
_repr__
     return('%s:%d' % ( self.name, self.type ))
TypeError: int argument required


If you have a look at the error message, it says:
   File "C:\Documents and Settings\Administrator\Desktop\phone.py", line 
23, in _
_repr__
     return('%s:%d' % ( self.name, self.type ))
TypeError: int argument required

If you have a look at your code, line 23 in phone.py:
         #  create string representation
         def __repr__(self):
                 return('%s:%d' % ( self.name, self.type ))

That means there is a problem with the integer argument of self.type, or 
sayd with other words, that your integer is, well... not an integer :-)

Try to find out why, and next time give us directly an error message, 
will make life easier for everyone :-)

Oh... and try also to deal with the random answer bug. Each time you 
give a random or empty answer, it exits with :
To see the 'test page' and exit the Database type the #: 3
: aqadasa or empty line
Traceback (most recent call last):
   File "test3.py", line 21, in ?
     b = input(':')
   File "<string>", line 0

     ^
SyntaxError: unexpected EOF while parsing

or:
NameError: name 'aqadasa' is not defined

The doc says for "input" among other things:
"Consider using the raw_input() function for general input from users."


Regards,

Guille


More information about the Tutor mailing list