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

1. [url]www.google.com[/url]
2. [url]www.facebook.com[/url]
....
107. [url]www.daniweb.com[/url]

and the result I want in the end: <p>1: <a href="www.google.com" target="blank">www.google.com</a></p> ..so 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?

Looks like homework.

What are the contents of data_list?

What do you need to do to each one?

Do function like:

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

>>> change(1, 'www.google.com')
'<p>1: <a href="www.google.com" target="blank">www.google.com</a></p>'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.