
June 15th, 2004, 08:49 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
Daves right as usual, but working with the info you've given and assuming that file 2 will be file 1 with some excess then you can do it really easily.
Code:
#!/usr/bin/env python
page1 = file('file1.txt', 'r').read()
page2 = file('file2.txt', 'r').read()
file('file3.txt', 'w').write(page2.replace(page1, ''))
This isn't going to be too efficent if the files are massive but for most things this should be file. Basically what it does is removes the common bit in the first page from the second
You can also do it like this, as sugested by Grim.
Code:
#!/usr/bin/env python
page1 = file('file1.txt', 'r').read()
page2 = file('file2.txt', 'r').read()
file('file3.txt', 'w').write(page2[len(page1):])
the down side to this being it doesnt actually do any comparison to check if the two parts of the file are the same though this would be easy enough to add. But then again, using the info you gave, theres no real need to do a comparison since we're assuming that both file start of the same  .
You might also want to take a look at filecmp or difflib in Pythons standard library:
http://www.python.org/doc/2.3.4/lib/module-filecmp.html
http://www.python.org/doc/2.3.4/lib/module-difflib.html
Hope this helps,
Mark.
__________________
programming language development: www.netytan.com – Hula
Last edited by netytan : June 15th, 2004 at 09:10 AM.
|