Split a string by a delimiter in python

前端 未结 3 1353
名媛妹妹
名媛妹妹 2020-11-22 06:58

How to split this string where __ is the delimiter

MATCHES__STRING

To get an output of [\'MATCHES\', \'STRING\']?

3条回答
  •  旧时难觅i
    2020-11-22 07:45

    You may be interested in the csv module, which is designed for comma-separated files but can be easily modified to use a custom delimiter.

    import csv
    csv.register_dialect( "myDialect", delimiter = "__",  )
    lines = [ "MATCHES__STRING" ]
    
    for row in csv.reader( lines ):
        ...
    

提交回复
热议问题