Python split string that have two delimited -
i want know how split string more 1 delimiter. have problem splitting if 1 space?
i trying read text file has this:
22.0;2016-01-16 00:16:18
i know how read text file variable, when have problem split string can't go further.
all have code:
with open('datasource_3.txt', 'r') f: data = f.readlines() line in data: words = line.strip().split(';') print words
you can split regular expression ;|
, so:
import re x = '22.0;2016-01-16 00:16:18' print re.split(';| ', x)
this prints ['22.0', '2016-01-16', '00:16:18']
.
Comments
Post a Comment