Traceback (most recent call last):
File "...\Hello Python\src\main\__init__.py", line 7, in <module>
redBench.accomodate(harold)
TypeError: unbound method accomodate() must be called with bench instance as first argument (got man instance instead)

Here is the code:

__init__py

import man_cl
import bench_cl

harold = man_cl.man("harold")
redBench = bench_cl.bench
[B]redBench.accomodate(harold)[/B]

man_cl.py

class man:
    def __init__(self, name):
        self.name = name
    def sit(self):
        print " is now sitting on bench"

bench_cl.py

class bench:
    occupants = []
[B]    def accomodate(self,person):
        self.occupants.append(person)
        print person.name + " now accomodated"[/B]
    def listOccupants(self):
        for i in range(1, occupants.__len__()):
            print "occupant number " + i + ": " + occupant[i].name

Any ideas?

For testing purposes I would write it like this ...

class Man(object):
    def __init__(self, name):
        self.name = name
    
    def sit(self):
        print " is now sitting on bench"


class Bench(object):
    def __init__(self):
        self.occupants = []
    
    def accomodate(self, person):
        self.occupants.append(person)
        print person.name + " now accomodated"
    
    def listOccupants(self):
        for i in range(0, len(self.occupants)):
            print "occupant number " + str(i+1) + ": " + self.occupants[i].name


harold = Man("harold")
redBench = Bench()
redBench.accomodate(harold)

larry = Man("larry")
redBench.accomodate(larry)

redBench.listOccupants()

Vegaseat,

Thanks! I think the error had to do mainly with the fact that I didn't create a constructor for the Bench class.

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.