PyH源码解析(2)steemCreated with Sketch.

in cn •  6 years ago 

生成Tag对象的属性

用户代码如下所示:

>>> a=div(a1='a1')
>>> print(a)
<div a1="a1">
</div>

在内部实现上,Tag对象的属性存放在一个字典中,字典的名字是attr,原来的名字是attributes,我觉得太长了,修改了一下。核心函数如下:

#把字典变成字符串,形如:' a="a" b="b"'
#需要注意的是class需要换成cl
renderAttr(self)->str
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!