• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python中反射用法实例

python中反射用法实例

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python脚本编写实例,python项目实例,python开发网站实例,python开发实例,python多线程实例等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了python中反射用法。分享给大家供大家参考。具体如下:

import sys, types,new
def _get_mod(modulePath):
  try:
    aMod = sys.modules[modulePath]
    if not isinstance(aMod, types.ModuleType):
      raise KeyError
  except KeyError:
    # The last [''] is very important!
    aMod = __import__(modulePath, globals(), locals(), [''])
    sys.modules[modulePath] = aMod
  return aMod
def _get_func(fullFuncName):
  """Retrieve a function object from a full dotted-package name."""
  # Parse out the path, module, and function
  lastDot = fullFuncName.rfind(u".")
  funcName = fullFuncName[lastDot + 1:]
  modPath = fullFuncName[:lastDot]
  aMod = _get_mod(modPath)
  aFunc = getattr(aMod, funcName)
  # Assert that the function is a *callable* attribute.
  assert callable(aFunc), u"%s is not callable." % fullFuncName
  # Return a reference to the function itself,
  # not the results of the function.
  return aFunc
def _get_Class(fullClassName, parentClass=None):
  """Load a module and retrieve a class (NOT an instance).
  If the parentClass is supplied, className must be of parentClass
  or a subclass of parentClass (or None is returned).
  """
  aClass = _get_func(fullClassName)
  # Assert that the class is a subclass of parentClass.
  if parentClass is not None:
    if not issubclass(aClass, parentClass):
      raise TypeError(u"%s is not a subclass of %s" %
              (fullClassName, parentClass))
  # Return a reference to the class itself, not an instantiated object.
  return aClass
def applyFuc(obj,strFunc,arrArgs):
  objFunc = getattr(obj, strFunc)
  return apply(objFunc,arrArgs)
def getObject(fullClassName):
  clazz = _get_Class(fullClassName)
  return clazz()
if __name__=='__main__':
  aa=getObject("inetservices.services.company.Company")  
  bb=applyFuc(aa, "select", ['select * from ngsys2',None])
  print bb
</div>

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

</div>

您可能想查找下面的文章:

  • python脚本爬取字体文件的实现方法
  • Python只用40行代码编写的计算器实例
  • Python实现脚本锁功能(同时只能执行一个脚本)
  • python脚本爬取字体文件的实现方法
  • python获取当前运行函数名称的方法实例代码
  • Python类的动态修改的实例方法
  • Python中动态创建类实例的方法
  • Python自动发邮件脚本
  • Python类的动态修改的实例方法
  • Python中动态创建类实例的方法

相关文章

  • python使用cookie库操保存cookie详解
  • python fabric实现远程部署
  • python的id()函数解密过程
  • python简单实现刷新智联简历
  • python使用socket创建tcp服务器和客户端
  • 在Windows系统上搭建Nginx+Python+MySQL环境的教程
  • python网络编程学习笔记(九):数据库客户端 DB-API
  • tensorboard实现同时显示训练曲线和测试曲线
  • python类继承用法实例分析
  • 教你用Type Hint提高Python程序开发效率

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • python检测远程udp端口是否打开的方法
    • Python实现截屏的函数
    • python实现搜索指定目录下文件及文件内搜索指定关键词的方法
    • Python 可爱的大小写
    • Python的净值数据接口调用示例分享
    • python基于mysql实现的简单队列以及跨进程锁实例详解
    • Python之Web框架Django项目搭建全过程
    • Python中字符串的处理技巧分享
    • Python文件操作类操作实例详解
    • 简单的Apache+FastCGI+Django配置指南

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有