0

I have a ".txt" file where I have a string say "Function supported" and "Function Description" I have multiple lines between these two string starting with say "-". How to get each line and apply some changes on it? To get the substring I can do :

substr = list[list.find("Functionality supported")+1:list.find("Functionality     Description")]
print ("Apply h1 to substr\n")

Will this helpful and if so how to apply only to text in each line not to "-". Also this "substr" has all those lines, should I apply split on substr , if so how?

thanks in advance -Pankaj

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
user1389673
  • 365
  • 1
  • 3
  • 6

1 Answers1

1

You can split the substring into separate strings:

substrings = substr.split('\n-')

Then apply the changes to each of the substrings, and finally join them back:

result = '\n-'.join(substrings)
Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
  • Sorry but this is not what I want as changes are to change the ".txt" to ".html" file with different formatting style , I mean the headers and change some headers to links and so on. – user1389673 Jun 26 '12 at 06:58
  • 1
    @user1389673: It is what you *asked* for. If you want something completely different than what you asked for, I suggest you start a new question, and ask what you want this time. Apparently you want to extract some data from a txt file and generate an HTML file from that. It's a very different question than the one you posed, where you want to "apply some changes" to some lines in a txt file. – Lennart Regebro Jun 26 '12 at 10:20