Start New Discussion within our Software Development Community

I have a file with bunch of lines and I want add html tag for in every line in file

1. [url][/url]
2. [url][/url]
107. [url][/url]

and the result I want in the end: <p>1: <a href="" target="blank"></a></p> I have 180 lines in the file and want all of lines have the tags as above

My python code for now:

#open file first
fobj = open("C:/Users/Ihsan/Desktop/links.txt", 'r+')
data_list = fobj.readlines()    #import into working environment
init, head, tail, end = "<p>", "<a href=\"", "\" target=\"blank\">", "</a></p>"

for i in data_list:   #call every item
    for link in i:
        begin = link.index("w") #know the first "h" index

so how to modify items in list?

Do function like:

>>> def change(ind, info):
	return '<p>%(ind)i: <a href="%(info)s" target="blank">%(info)s</a></p>' % locals()

>>> change(1, '')
'<p>1: <a href="" target="blank"></a></p>'
This article has been dead for over six months. Start a new discussion instead.