I am trying to accomplish what seems to be a simple task but I seem to be unable to figure it out. I am a Python rookie.
Here is my task:
I have a text file that contains a list of numbers, each on a separate line…
100101
100201
100301
100401
100501
100601
100701
100801
100901
101001
What I would like to do is read from the text file and write a new text file for each line in the file that contains the line and is also named using the line…
100101.txt
contains one line of text "100101"
100201.txt
contains one line of text "100201"
etc...
Hope this makes sense…thanks!
hjnathan
Try this:
Using the
withconstruct makes sure each file is closed when it’s not needed any longer (or if an exception should occur)