What you are doing wrong is not explicitly changing anything in any file.
Here is a little bit of code to show how to write stuff to files...
fp = open(somefilepath,'w')
this line opens a file for writing, the 'w' tells python to create the file if it does not exist, but also deletes the contents of the file if it does exist. If you want to open a file for writing and keep the current contents use 'a' instead. 'a' is for append.
fp.write(stuff)
writes whatever is in the variable 'stuff' to the file.
Hope this helps. For code more specific to your problem please tell us what exactly you want to write to your file.
Also, here is some documentation that should help you to better understand the topic of files: http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files
EDIT: but you are not changing anything!
By the end of your script here is what you have accomplished:
1. Dictionary is a set containing all acceptable words
2. WordList is a set containing all not acceptable lines
3. You have read to the end of SearchFile
If I am understanding your question correctly what you want to now do is:
4. find out which Disctionary word each line stored in Wordlist should be
5. re-write SearchFile with the offending lines replaced.
If this is correct, how do you intend to figure out which WordList entry is supposed to be which Dictionary entry? How do you know the actual corrections? Have you attempted this part of the script (it is the crux, after all. It would only be polite). Can you please share with us your attempt at this part.
Lets assume you have this function:
def magic(line,dictionary):
"""
this takes a line to be checked, and a set of acceptable words.
outputs what line is meant to be.
PLEASE tell us your approach to this bit
"""
if line in dictionary:
return line
...do stuff to find out which word is being mis spelt, return that word
Dictionary=set(open("dictionary.txt").read().split())
SearchFile = open("sample.txt",'r')
result_text = ''
for line in SearchFile:
result_text += magic(line.strip(),Dictionary) #add the correct line to the result we want to save
result_text += '\n'
SearchFile = open("sample.txt",'w')
SearchFile.write(result_text) # here we actually make some changes
If you have not thought about how to find the actual dictionary value that mis-spelt lines should be corrected to become, try this out: http://norvig.com/spell-correct.html
To re-iterate a previous point, it is important that you show that you have at least attempted to solve the crux of your problem if you want any meaningful help.