Ex48_convert.py

Somehow, I don’t think I am not doing this right. My thought process seems to be wrong.

Error TypeError: unbound method scan() must be called with Lexicon instance as first argument (got str instance instead)

This happens when I have tried importing. There for I can’t do test this way. I think I remember something about this when reading.

ex48.ex48_convert.py import Lexicon as lexicon

Code for ex48_convert.py

[code]
class Lexicon(object):

""" take in string value seperated by a space that describes a compass
    direction and then adds these to a list where each compass point is
    proceeded by the word "direction" eg [('direction', 'north')]
"""
    def __init__(self):
        self.sentence = []

    def scan(self, value):
        self.sentence = value.split()
        self.compass_direction()

    def compass_direction(self):

        for x in range(len(self.sentence)):
            if (self.sentence[x] == 'north' or self.sentence[x] == 'south' or
                self.sentence[x] == 'east' or self.sentence[x] == 'west'):
                self.sentence[x] = ('direction', self.sentence[x]) [/code]

How did other people do this exercise?

Never mind, I think I may already know

I would need to see how exactly you are using this as is most likely in your code here but in something else that uses this code.

I ended up deleting and re-writing the code like you say to do as well as getting out of the habit of asking questions when I really need to take a break and send myself a message. Cheers for the reply.

Nice, I’m a huge fan of burning bad code to the ground and starting over.