python实现得到一个给定类的虚函数

yipeiwu_com5年前Python基础

本文实例讲述了python实现得到一个给定类的虚函数的方法,分享给大家供大家参考。具体如下:

现来看看如下代码:

import wx 

for method in dir(wx.PyPanel):   #这里改成给定的类 
  if method.startswith("base_"): 
    print method 

输出的结果为:

base_AcceptsFocus
base_AcceptsFocusFromKeyboard
base_AddChild
base_DoGetBestSize
base_DoGetClientSize
base_DoGetPosition
base_DoGetSize
base_DoGetVirtualSize
base_DoMoveWindow
base_DoSetClientSize
base_DoSetSize
base_DoSetVirtualSize
base_Enable
base_GetDefaultAttributes
base_GetMaxSize
base_InitDialog
base_OnInternalIdle
base_RemoveChild
base_ShouldInheritColours
base_TransferDataFromWindow
base_TransferDataToWindow
base_Validate 

另附一个常用的str的方法,官方文档如下:
str.startswith(prefix[,start[,end]])

Return True if string starts with theprefix, otherwise returnFalse.prefix can also be a tuple of prefixes to look for. With optionalstart, test string beginning at that position. With optionalend, stop comparing string at that position.

如果string以prefix开头,函数返回True.

希望本文所述对大家的Python程序设计有所帮助。

相关文章

详解【python】str与json类型转换

在写接口测试框架时。避免不了数据类型的转换,比如强制转换string类型,比如转json类型 str转json python字符串转json对象,需要使用json模块的loads函数...

一键搞定python连接mysql驱动有关问题(windows版本)

对于mysql驱动问题折腾了一下午,现共享出解决方案 1:手动安装驱动 完全是场噩梦,推荐大家采用自动安装 2:自动安装 下载自动安装包,下载地址:https://www.jb51.ne...

Python Collatz序列实现过程解析

编写一个名为 collatz()的函数,它有一个名为 number 的参数。如果参数是偶数,那么 collatz()就打印出 number // 2, 并返回该值。如果 number 是...

对python中的os.getpid()和os.fork()函数详解

如下所示: import os import sys import time processNmae = 'parent' print "Program executing...

python将pandas datarame保存为txt文件的实例

CSV means Comma Separated Values. It is plain text (ansi). The CSV ("Comma Separated Value")...