数据属性的东西对我来说是新的,我刚刚意识到我需要转义空格、逗号等。有人能给我一些关于我的方法的建议吗?下面是我的代码:
#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)