[Tutor] class trouble
Kalle Svensson
kalle@lysator.liu.se
Sat, 20 Jul 2002 04:40:55 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
[Johannes Graumann]
> I'm just starting this and I'm absolutely clueless why the 3. and 4.
> print statements give me the errors they do. Please help!
> import string
> class porf:
> def __init__(self,name,sequence):
> self.name = name
> self.sequence = string.upper(sequence)
> def length(self):
> return len(self.sequence)
> def stats(self,aa):
> aa = string.upper(aa)
> return string.count(self.sequence,aa)
> ypr123a = porf('ypr123a','advboaisugvdfklabdfvlysgdvlajhsbfdlasgdclabhcd')
> print ypr123a.name
ypr123a
> print ypr123a.sequence
ADVBOAISUGVDFKLABDFVLYSGDVLAJHSBFDLASGDCLABHCD
> print ypr123a.length
A bit unexpected, maybe. Methods and functions are objects as any
other in Python, so this just prints the object.
<method porf.length of porf instance at 0x810d79c>
If you add parantheses to invoke the method, this is the result.
>>> print ypr123a.length()
46
> print ypr123a.stats('a')
6
What errors are you experiencing?
Peace,
Kalle
- --
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>
iD8DBQE9OM2zdNeA1787sd0RApbnAJ9rpBWxLwIxuG/LqWDHxQtCrW6hMQCfQXu3
ua5ix1C9y/phw6kweHoBOJo=
=KwIF
-----END PGP SIGNATURE-----