【发布时间】:2015-10-13 11:58:35
【问题描述】:
数据属性的东西对我来说是新的,只是意识到我需要转义空格、逗号等。有人可以就我的方法给我一些建议吗?以下是我的代码:
#A list holds all the strings to be sent to data-attribute,
#the sequence and length of the list is dynamic, determined by the user
#(That's why I need to find a way to escape automatically.
Apt_p = []
Apt_p.append('Relative to planting')
Apt_p.append('Relative to harvest')
Apt_p_j=json.dumps(Apt_p) #convert everything into JSON for future usage
#I think below is the place to let escape happen.
html = """<td id="Apt_p_j" data-val=%s></td>""" %(Apt_p_j)
【问题讨论】:
标签: json html custom-data-attribute