AutoComplete plugin part1
2
Part 1 of an autocomplete plugin designed for use in IMs. Not entirely finished since if two new words are used in one string then it doesn't add them correctly - starting with a full wordlist would reduce the chance of this occurring however.
#Part 1 - Adding words from a string to a wordlist with number of times added
#TODO: If new word is used twice it adds twice - URGENT
string = raw_input("Enter string to be added to wordlist: ")
string = string.replace("\n", "") #Remoe Punctuation search for repeat words
string = string.replace(",", "")
string = string.replace(".", "")
string = string.lower()
lastspace=-1
readme=open("dict.txt", "r+w")
readfile = readme.read()
readme.seek(0)
for i in range(string.count(" ") + 1):
nextspace=string.find(" ", lastspace + 1) #Use split(" ") to split spaces instead
if nextspace==-1:
nextspace=len(string)
word=string[lastspace + 1:nextspace]
print word
wordinstr=string.count(word)
#string.replace(word, "", wordinstr-1) #FIX me - needs to repalce from back forward not this way
cword=readfile.count(word)
#print cword
if cword ==0:
readme.seek(-0,2)
readme.write(word + "," + repr(wordinstr) + "\n")
#This is the hard part :(
else:
stapos=readfile.index(word)
numpos=stapos + len(word) + 1
readme.seek(0)
#orino=readfile[numpos]
# newno=orino+1
for j in range(len(readfile)):
curchar=readfile[j]
if j==numpos:
curchar=int(curchar)
curchar+= wordinstr
curchar=repr(curchar)
readme.write(curchar)
lastspace=nextspace
readme.close()






There are currently no comments for this snippet.