python动态import
来源:互联网 发布:c2运输机知乎 编辑:程序博客网 时间:2024/06/06 02:00
一个例子
目录结构如下:
.├── student.py└── test.py
student.py:
class Student(object): def say(self): return 'student'
test.py:
module_name = __import__('student', fromlist=['Student'])class_name = getattr(module_name, 'Student')print class_name().say()
注意:
__import__('A.B.C', fromlist=[])
时,即fromlist
为空时,函数返回的是moduleA
;当fromlist
不为空时,函数返回的是moduleC
。
Ref
Why does Python’s __import__
require fromlist?
阅读全文
0 0
- python动态import
- python import、from import
- Python import
- Python import
- Python import
- Python import
- python import
- python import
- Python-import
- Python import
- Python import
- python:import
- python import
- python import
- python动态import某个文件夹下的模块
- Python Gossip: import、import as、from import
- python import 与from ... import
- 【Python】import class/import module
- 【数据结构】查找算法 Python 版
- Javase—循环语句
- 实验吧-NSCTF web200 writeup
- 线程监控
- Error:JAVA_HOME is not set and could not be found
- python动态import
- POJ 2983 Is the Information Reliable?(差分约束+SPFA+超级源点)
- 选择某种Map集合保存学号从1到15的学员的学号(键)和姓名(值),学号用字符串表示,输入的时候要以学号乱序的方式存入Map集合,然后按照学号从大到小的顺序将Map集合中的元素输出打印。需要自定义Ma
- 如何简单形象又有趣地讲解神经网络是什么?
- ubuntu重装与挂载
- 2017.11.26 刘明春第四天总结
- 包含负整数的桶排序
- HDU 5701-中位数计数
- WeakHashMap 原理