What I am trying to achieve is to separate up a list of entries in a single file into multiple files as follows.
www.a.com/thing1.html www.b.com/thing2.html www.c.com/thing3.html
And save the single line entries into files, where a new file would look like this
For example the first entry-
Filename would be
Contents in the file would be:
[some static text common to all files]www.a.com/thing1.html[more static content]
And have this run as a loop on all entries in the list file until exhausting the list. Not sure if a for loop will work here, or a while loop.
I've just begun learning python, and some of these functions (creating files, specifying filenames) are still foreign to me.
preguntado el 01 de febrero de 12 a las 22:02
I am telling you for a single file but for your case you can iterate over your list para lograr lo mismo.
>>> st = "www.a.com/thing1.html" >>> filename = re.findall(r"/(\w+).",st) >>> filename ['thing1'] >>> filename = "".join(filename) + '.txt' >>> filename 'thing1.txt' >>> f = open(filename,'w') >>> f.writelines(st)
También puede pasar un
mylist = ["some static text common to all files",st,"more static content"] f.writelines(mylist)