[Tutor] inquire
XIA Xiao-Qin
XQ.Xia@ccsr.cam.ac.uk
Mon, 15 Jan 2001 18:38:03 +0000
--=====_97958388318467=_
Content-Type: text/plain; charset="WINDOWS-1250"
Content-Transfer-Encoding: quoted-printable
Dear Sir / Madam,
Excuse me -- I have questions again.
1.Is there any way to know the type of a variable in Python.
for example:
def deal(*options):
for k in options:
if k is a list: # Can I get to know the type of k?
my_function_for_list()
elif k is a class:
my_function_for_class()
2. Can a method know the name of the class in which the method is defined?
class A:
def fun(self):
print self.__class__.__name__ # perhaps print 'A' or ''D', ...
print A.fun.im_class.__name__ # Is here any way to print 'A' at=
any time without using A directly?
class B(A):
pass
class C(B):
pass
class D(C):
def newfun(self):
B.fun(self)
And can we print the name of class B? by modify the methods fun(self) and=
newfun(self)?
Sincerely yours,
Xia XQ
--=====_97958388318467=_
Content-Type: text/html; charset="WINDOWS-1250"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>
<META content="text/html; charset=windows-1250" http-equiv=Content-Type>
<META content='"MSHTML 4.72.3612.1700"' name=GENERATOR>
</HEAD>
<BODY bgColor=#ffffff style="FONT-FAMILY: Arial" text=#000000>
<DIV><FONT color=#000000 size=2>Dear Sir / Madam,</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT> </DIV>
<DIV><FONT color=#000000 size=2>Excuse me -- I have questions
again.</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT> </DIV>
<DIV><FONT size=2>1.Is there any way to know the type of a variable in
Python.</FONT></DIV>
<DIV><FONT size=2>for example:</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>def deal(*options):</FONT></DIV>
<DIV><FONT size=2> for k in options:</FONT></DIV>
<DIV><FONT size=2> if k is a
list: # Can I get to know the type of k?</FONT></DIV>
<DIV><FONT
size=2>
my_function_for_list()</FONT></DIV>
<DIV><FONT size=2> elif k is a
class:</FONT></DIV>
<DIV><FONT
size=2>
my_function_for_class()</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>2. Can a method know the name of the class in which the method
is defined?</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV>class A:<BR> def fun(self):<BR>
print self.__class__.__name__ # perhaps print 'A' or
''D', ...</DIV>
<DIV> print
A.fun.im_class.__name__ # Is here any way to print 'A' at any
time without using A directly?</DIV>
<DIV> <BR>class B(A):</DIV>
<DIV> pass</DIV>
<DIV> <BR>class C(B):<BR> pass</DIV>
<DIV> </DIV>
<DIV>class D(C):<BR> def
newfun(self):<BR> B.fun(self)<BR></DIV>
<DIV><FONT size=2>And can we print the name of class B? by modify the methods
fun(self) and newfun(self)?</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>Sincerely yours,</FONT></DIV>
<DIV><FONT size=2>Xia XQ</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV></BODY></HTML>
--=====_97958388318467=_--