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

yipeiwu_com6年前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程序设计有所帮助。

相关文章

pycharm 将python文件打包为exe格式的方法

pycharm 将python文件打包为exe格式的方法

因为近期正在学习python,就需要将python文件打包为exe可执行文件,就将该过程记录下来。 首先我是通过Pyinstall打包的,具体安装及打包步骤如下 1.打开终端控制台 通过...

python 获取键盘输入,同时有超时的功能示例

如下所示: ''' ###get keyboard input and timeout =5 import sys, time, msvcrt def readInput( ca...

Flask数据库迁移简单介绍

前言 用过Django的小伙伴都知道,Django的ORM是自带的,比较特殊,而且集成了很多功能,比如数据库迁移… 何为ORM,个人之见解,简化sql语句的书写,将关系型数据库的一张张...

基于pycharm导入模块显示不存在的解决方法

基于pycharm导入模块显示不存在的解决方法

最近,同级或者不同级目录下,导入某个模块,显示不存在,可明明存在,百度找了好多没找到,试了 import sys sys.path.append('/path/to/test') /...

用Python代码来解图片迷宫的方法整理

用Python代码来解图片迷宫的方法整理

译注:原文是StackOverflow上一个如何用程序读取迷宫图片并求解的问题,几位参与者热烈地讨论并给出了自己的代码,涉及到用Python对图片的处理以及广度优先(BFS)算法等。 问...