python分隔字符串

输入字符串:word_12313.png,Latin,L'ESPACE,

希望获得:img_name='word_12313.png', script='Latin', content="L'ESPACE,"。注意content中可能也含有分隔符','!

a = "word_12313.png,Latin,L'ESPACE,"
al = a.strip().split(',')    # ['word_12313.png', 'Latin', "L'ESPACE", '']
img_name = al[0]
script = al[1]
del al[:2]    # 删除前两个元素,剩下元素都是由逗号拆分的, ["L'ESPACE", '']
content = ','.join(al)    # "L'ESPACE,"

猜你喜欢

转载自blog.csdn.net/qq_27061325/article/details/84678817
今日推荐