I am trying to join every_line in a txt file with a header text. But after successfully joining
up the lines. I cannot seem to write the file correctly as it will only write the last joined line into the internallinks.txt
. How can I make it to write the whole output of combined
into the file?
Any help would be appreciated, thank you very much!
Python code
with open(r"C:\Users\xingj\Desktop\writing.txt") as f:
internallink = ("www.icom.org.cn")
for every_line in f:
combined = (internallink + every_line.strip())
out_str = "".join(combined)
with open("C:\\Users\\xingj\\internallinks.txt",'w') as b:
b.write(out_str)
Content of writing.txt
/icom/faculty/viewer/?id=1122
/icom/faculty/viewer/?id=1125
/icom/faculty/viewer/?id=586&
/icom/faculty/viewer/?id=1126
/icom/faculty/viewer/?id=470&
Output of internallinks.txt
www.icom.org.cn/icom/faculty/viewer/?id=470&
Output of command print (combined)
before with
is closed
PS C:\Users\xingj> & python c:/Users/xingj/testingagain.py
www.icom.org.cn/icom/faculty/viewer/?id=1122
www.icom.org.cn/icom/faculty/viewer/?id=1125
www.icom.org.cn/icom/faculty/viewer/?id=586&
www.icom.org.cn/icom/faculty/viewer/?id=1126
www.icom.org.cn/icom/faculty/viewer/?id=470&
PS C:\Users\xingj>