[Tutor] using class methods (security)
Karthik_Gurumurthy@i2.com
Karthik_Gurumurthy@i2.com
Fri, 26 Apr 2002 07:24:17 +0530
This is a multipart message in MIME format.
--=_alternative 000A769465256BA7_=
Content-Type: text/plain; charset="us-ascii"
I have a few questions about this:
> (1) Looking over the documentation, I have noticed that in
> python 2.2, you have to subclass every class. If there is no
> super class to base your new class, then you have to use the
> default "(object)". Am I correct?
No. Actually you need to specify "object" as the super class only if you
intend to use some nice
python2.2 features like properties etc.
Further, i noticed that having "object" @ the top gives the exact type of
the object am working with.
But then, i guess, for a dynamically typed language like python, i s'd'nt
be writing code based on the
current type of the object!
Anyways I have done a cut-paste of an idle session..
Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> class test:
pass
>>> t = test()
>>> type(t)
<type 'instance'>
>>> class test(object):
pass
>>> t = test()
>>> type(t)
<class '__main__.test'>
>>>
> (2) If I am right in number (1), then I really should get python
> 2.2. Otherwise, I will be writing code that will eventually be
> incompatible.
So if you don't plan to use python2.2 features, i guess most of your code
s'd'nt break.
am not aware of subtle changes in the versions.
regards,
karthik
--=_alternative 000A769465256BA7_=
Content-Type: text/html; charset="us-ascii"
<br>
<br>
<br><font size=2 face="Courier New">I have a few questions about this:<br>
<br>
> (1) Looking over the documentation, I have noticed that in<br>
> python 2.2, you have to subclass every class. If there is no<br>
> super class to base your new class, then you have to use the<br>
> default "(object)". Am I correct?</font>
<br>
<br><font size=2 face="Courier New">No. Actually you need to specify "object" as the super class only if you intend to use some nice</font>
<br><font size=2 face="Courier New">python2.2 features like properties etc.</font>
<br>
<br><font size=2 face="Courier New">Further, i noticed that having "object" @ the top gives the exact type of the object am working with.</font>
<br>
<br><font size=2 face="Courier New">But then, i guess, for a dynamically typed language like python, i s'd'nt be writing code based on the </font>
<br><font size=2 face="Courier New">current type of the object!</font>
<br>
<br><font size=2 face="Courier New">Anyways I have done a cut-paste of an idle session..</font>
<br>
<br><font size=2 face="Courier New">Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32</font>
<br><font size=2 face="Courier New">Type "copyright", "credits" or "license" for more information.</font>
<br><font size=2 face="Courier New">IDLE 0.8 -- press F1 for help</font>
<br><font size=2 face="Courier New">>>> class test:</font>
<br><font size=2 face="Courier New"> pass</font>
<br>
<br><font size=2 face="Courier New">>>> t = test()</font>
<br><font size=2 face="Courier New">>>> type(t)</font>
<br><font size=2 face="Courier New"><type 'instance'></font>
<br><font size=2 face="Courier New">>>> class test(object):</font>
<br><font size=2 face="Courier New"> pass</font>
<br>
<br><font size=2 face="Courier New">>>> t = test()</font>
<br><font size=2 face="Courier New">>>> type(t)</font>
<br><font size=2 face="Courier New"><class '__main__.test'></font>
<br><font size=2 face="Courier New">>>> </font>
<br>
<br><font size=2 face="Courier New"><br>
<br>
> (2) If I am right in number (1), then I really should get python<br>
> 2.2. Otherwise, I will be writing code that will eventually be<br>
> incompatible.</font>
<br>
<br><font size=2 face="Courier New">So if you don't plan to use python2.2 features, i guess most of your code s'd'nt break.</font>
<br><font size=2 face="Courier New">am not aware of subtle changes in the versions.<br>
</font>
<br><font size=2 face="Courier New">regards,</font>
<br><font size=2 face="Courier New">karthik</font>
<br>
<br>
--=_alternative 000A769465256BA7_=--