Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4271482
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:26:54+00:00 2026-05-21T07:26:54+00:00

I am trying to learn python, the guide I am following is asking me

  • 0

I am trying to learn python, the guide I am following is asking me to write a simple ‘game’, utilizing tuples, lists, and classes.

When running the ‘nosetests’ command, I get the following error:

E.
====================================================================== ERROR:
tests.LEXICON_tests.test_directions
---------------------------------------------------------------------- 
Traceback (most recent call last):  
File "/Library/Python/2.6/site-packages/nose/case.py",
line 187, in runTest
   self.test(*self.arg)   
File "/Users/VB/Documents/svn/Programming/python/projects/lexicon/tests/LEXICON_tests.py",
line 6, in test_directions
   assert_equal(lexicon.scan("north"),
[('directions', 'north')]) TypeError:
unbound method scan() must be called
with lexicon instance as first
argument (got str instance instead)

---------------------------------------------------------------------- Ran 2 tests in 
 0.011s

 FAILED (errors=1) VB MP > ./lexicon.py

 > north [(), ('directions', 'north')] VB MP > ./lexicon.py 
 > north south east [[[(), ('directions', 'north')],
 ('directions', 'south')],
 ('directions', 'east')] VB MP 

main file:

#!/usr/bin/env python
# encoding: utf-8

import sys
import os
from LEXICON.game import lexicon


def main():
    stuff = raw_input('> ') 

    lex = lexicon (stuff)

    split_array = lex.scan(stuff)
    print split_array

    #me = lex.tockens(split_array)
    #print me

if __name__ == '__main__':
    main()

class 
#!/usr/bin/env python
# encoding: utf-8
"""

import sys
import os

class lexicon (object):
    def __init__(self,data):
        self.direction = data
        #self.words = data.split()

    def scan(self,data):
        split_data = data.split()
        lex = lexicon (data)

        tocken = lex.tockens(split_data)


        return tocken

    def tockens(self,splitdata):

        sentence = splitdata
        verbs = ['go','swim','open','punch','fly','stop','kill','eat']
        objekts = ['door','bear','face','princess','cabinet']
        directions = ['north','south','east','west','down','up','left','right','back']
        stopwords = ['the','in','of','from','at','it']


        # setep 1, open the array

        bit = ()
        byte = ()
        for x in sentence:
            # step 2, match against verbs
            for v in verbs:
                try:
                    if (x == v):
                        bit = ('verb',x)
                        byte = [byte, bit]              
                except ValueError:
                    print "Ooops!"
            for o in objekts:
                try:
                    if (x == o):
                        bit = ('objekt',x)
                        byte = [byte, bit]
                except ValueError:
                    print "Ooops!"
            for d in directions:
                try:
                    if (x == d):
                        bit = ('directions',x)
                        byte = [byte, bit]
                except ValueError:
                    print "Ooops!"
            for s in stopwords:
                try:
                    if (x == s):
                        bit = ('stopwords',x)
                        byte = [byte, bit]
                except ValueError:
                    print "Ooops!"

        return byte

test

from nose.tools import *
#import LEXICON
from LEXICON.game import lexicon

def test_directions(): 
    assert_equal(lexicon.scan("north"), [('directions', 'north')]) 
    result = lexicon.scan("north south east") 
    assert_equal(result, [('directions', 'north'),
                          ('directions', 'south'), 
                          ('directions', 'east')])

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:26:55+00:00Added an answer on May 21, 2026 at 7:26 am

    The way methods are called in python is that the object it is called on is passed as the first argument, and the arguments supplied are each pushed down 1. When you call like its a static method (lexicon.scan) instead of an instance method (lex.scan) this first argument is not supplied.

    The method lexicon.scan requires the first argument be a “lexicon” type object, so what you probably want to do in your test is to create a lexicon object (lex = lexicon(stuff)) and call scan from that object (lex.scan("north")). As is, it is calling scan("north"), while you want the call to be scan(lex, "north").

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to learn doxygen by running following Python file. A similar attempt
I'm trying to learn python and I'm attempting a hangman game. But when I
I was trying to learn how to profile a simple python program using hotshot,
I'm brand new to Python and trying to learn it by replicating the following
I am trying to learn python, I was trying write C/C++ code i used
I'm trying to learn python, so I decided to write a script that could
Trying to learn some geospatial python. More or less following the class notes here
I'm trying to learn the classes in python: #!/usr/bin/env python # *-* coding: utf-8
I'm trying to learn Python, (i have 2.5.4) by writing a snake game, but
I am trying to learn Python lists. In this code I am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.