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

相关文章

Python 中 Virtualenv 和 pip 的简单用法详解

本文介绍了Python 中 Virtualenv 和 pip 的简单用法详解,分享给大家,具体如下: 0X00 安装环境 我们在 Python 开发和学习过程中需要用到各种库,然后在各个...

Python中flatten( )函数及函数用法详解

flatten()函数用法 flatten是numpy.ndarray.flatten的一个函数,即返回一个一维数组。 flatten只能适用于numpy对象,即array或者mat,普...

pytorch 归一化与反归一化实例

ToTensor中就有转到0-1之间了。 # -*- coding:utf-8 -*- import time import torch from torchvisi...

Python命名空间详解

通俗的来说,Python中所谓的命名空间可以理解为一个容器。在这个容器中可以装许多标识符。不同容器中的同名的标识符是不会相互冲突的。理解python的命名空间需要掌握三条规则: 第一,赋...

Python Django中间件,中间件函数,全局异常处理操作示例

Python Django中间件,中间件函数,全局异常处理操作示例

本文实例讲述了Python Django中间件,中间件函数,全局异常处理操作。分享给大家供大家参考,具体如下: 应用名/middleware.py(定义中间件类,中间件函数。文件名可以任...