___  ___    _ _    _  _ _____   _____
 / __|/ _ \  | | |  | || |_ _\ \ / / __|
| (_ | (_) | |_  _| | __ || | \ V /| _|
 \___|\___/    |_|  |_||_|___| \_/ |___|

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

PyH源码解析(4)

BY: @brysj22952 | CREATED: Aug. 11, 2018, 8:31 a.m. | VOTES: 2 | PAYOUT: $0.00 | [ VOTE ]

增加兄弟Tag对象

这个实际上就是Tag对象的序列,如下所示:

>>> a=div('a1')+div('a2')+div('a3')
>>> print(a)

a1



a2



a3

其实现原理就是重载了+操作符,上面例子中的返回对象a是一个特殊的Tag对象,它没有tagname,它的isSeq属性为True,表示它容纳了一个Tag的序列。

为Tag对象追加内容和子对象

这里使用了<<符号,如下示例:

>>> a=div()
>>> a<<'test'
>>> a<>> print(a)


test




其实现原理很简单,就是直接调用self.addObj()即可。只不过需要注意的是,其返回对象是其子Tag对象,以便<<可以连续使用。另外需要注意的是,如果追加的tag是一个序列Tag对象,则把它展开,每一个成员作为子Tag追加。

TAGS: [ #cn ] [ #pyh ] [ #sourcecode ] [ #anylyse ]

Replies

@redwanmiazee10 | Aug. 11, 2018, 8:32 a.m. | Votes: 0 | [ VOTE ]

Exclusive offer GET 5 STEEM Airdrop
Join our Site and get 5 steem airdrop on your steem account. The Campaign has start for attract new user to use our service and mass adoption.
Get 5 STEEM NOW CLICK HERE

@arcange | Aug. 11, 2018, 8:33 a.m. | Votes: 0 | [ VOTE ]

WARNING - The message you received from @redwanmiazee10 is a CONFIRMED SCAM!
DO NOT FOLLOW any instruction and DO NOT CLICK on any link in the comment!

For more information about this scam, read this post:
https://steemit.com/steemit/@arcange/phishing-site-reported-steembottracker-dot-trade

If you find my work to protect you and the community valuable, please consider to upvote this warning or to vote for my witness.

[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>