两个重要的东西:
-
coroutine
-
yield from 或者 async/await (but just only python3.5+)
其实还有一些也是挺重要的,比如decorator(但是我比较懒。。。。。)
在整个过程中充满了激情。。。。(流泪~~
在动态导入url handler时,总是获取不到method和path的属性
这是一段当时的代码(mod是通过__import__函数加载的)
for attr in dir(mod):
if attr.startswith('_'):
continue
method = getattr(attr, '__method__',None)
path = getattr(attr, '__route__',None)
if method and path:
add_route(app, attr)
当时我竟然怀疑难道是__import__()函数和import语句不一致吗???
想不到我还是这么的天真无鞋。。。。。。
经过Google竟然没有发现类似的问题
于是乎,自己写了一个test,并使用import语句导入
妈蛋,使用import语句可以读取到(这使我加深了对__import__函数的怀疑
然并卵,看到这行代码的时候我忽然想到了什么。。。。
if attr.startswith('_'):
对,attr是str类型的。。。。。。(此时我真想抽自己两巴掌
最后再次通过getattr函数读取attr属性,url handler总算添加进去了
最后的最后,无节操的贴个源码(哈哈