What I’m looking for is take a specific chunk or segment from text file. How can I indicate to Python where to start and finish the reading or printing? I found this example code but I couldn’t find an explanation for this particular technique. I know how to use the method “.split()” with strings but there are additional parameters that I don’t understand.
a = open("text_1.txt", "r")
text = a.read()
print (text.split("<--")[1].split("-->")[1])
# Here this code splits the text on the text file, starting from
# the value inside of the second ".split()" and ends in the value
# inside the first. What I don't understand what means the one in brackets `[1].`
a.close()
As you may already notice, in this case, the text I want to print is between "--> ..... and ..... <--" symbols.
In addition, What if there are not symbols to delimit the text?, What if I would like to isolate a whole paragraph, without lossing the first and last words? What if there is more than one word or symbol that is specified inside the ".split( )" method?
Is there any way to indicate Python that I want to select lines according its line-number (in the case of importing a web page with urllib)?
Thanks in advance