I am using split() to parse till a colon. I have several colons in my text but I just need the string from the first line. What i need to do to just get the first line?
line = """Hello :
This is a test ......:
Testpath: C:\\...
blablablabla
123:"""
if ' :' in line:
av = line.split(" :",1)[0]
print av
Is it possible to access the first line without using regexpression??
If I understood your question correctly, you want to print only the first line of the multi-lined string irrespective of colon as separator. If this is the case, here is my possible solution (for windows os):
line = """ bravo cos
daring in the blah blah."""
The soln is:
print(line.split("\n")[0])
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With