werkzeug.utils.import_string的用处

def from_object(self, obj):
    if isinstance(obj, string_types):
       obj = import_string(obj)
   for key in dir(obj):
     if key.isupper():
         self[key] = getattr(obj, key)

    在flask app.py的源代码中看到import_string,往上看是出自werkzeug.utils,看了下文档:

werkzeug.utils. import_string ( import_name, silent=False )

Imports an object based on a string. This is useful if you want touse import paths as endpoints or something similar. An import path canbe specified either in dotted notation (xml.sax.saxutils.escape)or with a colon as object delimiter (xml.sax.saxutils:escape).

If silent is True the return value will be None if the import fails.

Parameters:
  • import_name – the dotted name for the object to import.
  • silent – if set to True import errors are ignored andNone is returned instead.
Returns:

imported object

    用cmd测试了下werkzeug.utils.import_string()就是用来导入函数的

>>> import_string('config.TestingConfig')
<class config.TestingConfig at 0x0000000002A8F708>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值