i'm thinking maybe it's an indentation problem but I don't know

while if elif else while if elif continue if ..... a mess where am i now:confused:
Most can understand a while if elif else..,but if you nest it together then code lose readability.

The code will be much harder to debug/troubleshoot.
Write more function like you start of with,good code almost need no documentation.
I see you have get good help before in this post,i did start to look at your code but i lost motivation because of reason explaind.

Ok well I make a backup of my code yesterday that I KNOW works and yet it gave me the same error. Can someone actually test the code I put and see if they get the same error?

Alright,
I have worked around the fact that I can't seem to assign the cutstart and cutend variables in my code. I am so close to the jackpot!!!

EDIT: I decided to put each rule and response in a list. I am testing the program so far with no problems...

Pretty big problem :(, but it looks to be the last one I will get :)
Say the rules file looks like this:

remember <this> | Sure I will, but only because it's a <weather> day
remember <w1> | Not until you tell me the weather
the weather is <weather> | Thanks, I'll remember that
testmem | I'm sorry to say, I do in fact remember <this>
testmem | Guess what? I have no recollection of this thing

Note you are required to store the matched <> words in a dictionary for later use, as you can see.

Now, the output for the following list of inputs should look like this:

> the weather is fine
Thanks, I'll remember that
> remember birthdays
Sure I will, but only because it's a fine day
> testmem
I'm sorry to say, I do in fact remember birthdays

Instead I get:

> the weather is fine
Thanks, I'll remember that
> remember birthdays
Sure I will, but only because it's a fine day
> testmem
Not until you tell me the weather
> testmem
I'm sorry to say, I do in fact remember birthdays
> testmem
Guess what? I have no recollection of this thing

I just don't seem to be storing the words to the dictionary properly or something... I just don't really know :(
Note when I testmem again, it will say "I'm sorry to say, I do in fact remember birthdays" and again, "Guess what? I have no recollection of this thing" when it should always be saying "I'm sorry to say, I do in fact remember birthdays" :(

My code:

import re
import string
template_re = re.compile(r"<\w+>")
def template_helper(match):
    return "(?P{0}(?:\w|[!#$%&'()*+,-./:;<=>?@[\]^_`|~])+)".format(match.group(0))

def multiwordReplace(cutend, dicto):
    for key in dicto:
        cutend = cutend.replace(key, dicto[key])
    return cutend

def multiwordReplace(cutend1, dicto):
    for key in dicto:
        cutend1 = cutend1.replace(key, dicto[key])
    return cutend1

dicto = {}
dicti = {}
input_words = raw_input("Hello, my name is Eliza. What would you like to talk about?\n> ")
while True:
    input_a = []
    dicti = {}
    for item in input_words.split():
        item = item.strip(string.punctuation)
        input_a.append(item)
    input_b = ' '.join(input_a)
    lower_input = input_b.lower()
    
    rules = open("rules.txt", "rU")
    go_on = True    

    rulesl = []
    responsesl = []
    for line in rules:
        a,b = line.split(" | ")
        b = b.strip("\n")
        rulesl.append(a)
        responsesl.append(b)        
    for item in xrange(len(rulesl)):
        cutstart=rulesl[item]
        cutend=responsesl[item]
        template = cutstart
        regex = template_re.sub(template_helper, template)
        regex = re.compile(regex)
        match = regex.search(lower_input)        
     
   
        if match is not None:
            cutend1 = cutend
            dicti = dicto.copy()
            for i in cutstart.split():                       
                if i[0] =="<" and i[-1] ==">":
                    worda = i.strip("<>")
                    x, y = match.span(worda)
                    word1 = (input_b[x:y]).strip(string.punctuation)
                    dicto[i] = word1
            cutend1 = multiwordReplace(cutend1, dicto)
            if "<" in cutend1:           
                dicto = dicti.copy()              
                continue
            elif "<" not in cutend1:                
                cutend = multiwordReplace(cutend, dicto)
                input_words = raw_input(cutend + "\n> ")
                go_on = False
        if match is None:
            continue
            
    if go_on:
        input_words = raw_input("Please go on.\n> ")
    if input_words == "":
        break

HELP IF YOU CAN PLEASE!!! :(

I don't see how your code can handle several rules with the same 'cutstart', nor where your code stores words for later use. I agree with snippsat: you should write functions to clarify the algorithm. There are other errors, look at this:

>>> cutstart = "hello > world"
>>> if "<" and ">" in cutstart:
...  print "wow"
... 
wow

but cutstart doesn't contain "<".

Ok after a VERY long time coding this program, I have completed it. It turns out when I used "continue" it went to test the next line of the rules.txt with the same input instead of doing all that stuff before it eg. converting to lowercase.

Can I just say, Gribouillis, mate, YOU ARE A LEGEND!!!! THANK YOU SO MUCH!!!

I couldn't have done it without you man.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.