Answer the question
In order to leave comments, you need to log in
How to split 2 strings?
Let's say I have a file in which I have certain data written:
"Xxxxx : Yyyyy" They are separated by a
colon.
How can I do that. What would it all be written in a separate variable, i.e.
First = "Xxxxx"
Second = "Yyyyy"
Is it possible to do this?
Answer the question
In order to leave comments, you need to log in
In [1]: f, s = "Xxxxx : Yyyyy".split(' : ')
In [2]: f, s
Out[2]: ('Xxxxx', 'Yyyyy')
>>> import os
>>> os.system('cat a.txt')
aaa:bbb
0
>>> with open('a.txt') as a:
... a,b = a.readline() .replace('\n', '').split(':')
...
>>> a
'aaa'
>>> b
'bbb'
>>>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question