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 7814793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:18:38+00:00 2026-06-02T05:18:38+00:00

I have a class, and I would like to be able to create multiple

  • 0

I have a class, and I would like to be able to create multiple objects of that class and place them in an array. I did it like so:

    rooms = []
    rooms.append(Object1())
    ...
    rooms.append(Object4())

I then have a dict of functions, and I would like to pass the object to the function. However, I’m encountering some problems..For example, I have a dict:

    dict = {'look': CallLook(rooms[i])}

I’m able to pass it into the function, however; in the function if I try to call an objects method it gives me problems

    def CallLook(current_room)
       current_room.examine()

I’m sure that there has to be a better way to do what I’m trying to do, but I’m new to Python and I haven’t seen a clean example on how to do this. Anyone have a good way to implement a list of objects to be passed into functions? All of the objects contain the examine method, but they are objects of different classes. (I’m sorry I didn’t say so earlier)

The specific error states: TypeError: ‘NoneType’ object is not callable

  • 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-06-02T05:18:40+00:00Added an answer on June 2, 2026 at 5:18 am

    Anyone have a good way to implement a list of objects to be passed into functions? All of the objects contain the examine method, but they are objects of different classes. (I’m sorry I didn’t say so earlier)

    This is Python’s plain duck-typing.

    class Room:
        def __init__(self, name):
            self.name = name
        def examine(self):
            return "This %s looks clean!" % self.name
    
    class Furniture:
        def __init__(self, name):
            self.name = name
        def examine(self):
            return "This %s looks comfortable..." % self.name
    
    def examination(l):
        for item in l:
            print item.examine()
    
    list_of_objects = [ Room("Living Room"), Furniture("Couch"), 
                        Room("Restrooms"), Furniture("Bed") ]
    examination(list_of_objects)
    

    Prints:

    This Living Room looks clean!
    This Couch looks comfortable...
    This Restrooms looks clean!
    This Bed looks comfortable...
    

    As for your specific problem: probably you have forgotten to return a value from examine()? (Please post the full error message (including full backtrace).)

    I then have a dict of functions, and I would like to pass the object to the function. However, I’m encountering some problems..For example, I have a dict:

    my_dict = {'look': CallLook(rooms[i])} # this is no dict of functions
    

    The dict you have created may evaluate to {'look': None} (assuming your examine() doesn’t return a value.) Which could explain the error you’ve observed.
    If you wanted a dict of functions you needed to put in a callable, not an actual function call, e.g. like this:

    my_dict = {'look': CallLook} # this is a dict of functions
    

    if you want to bind the 'look' to a specific room you could redefine CallLook:

    def CallLook(current_room)
       return current_room.examine # return the bound examine
    my_dict = {'look': CallLook(room[i])} # this is also a dict of functions
    

    Another issue with your code is that you are shadowing the built-in dict() method by naming your local dictionary dict. You shouldn’t do this. This yields nasty errors.

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

Sidebar

Related Questions

I have a class that is called regularly by several objects. I would like
I would like to have a private property in a class, and be able
I have a class that I would like to use in a scala.collection.mutable.PriorityQueue, but
I have a class in silverlight that I would like to store to disk.
I have a class that is marked with DataContract attributes and I would like
I have a class that contains decoded video frames. I would like my decoder
I would like to create a class that describes a file resource and then
Supposed I have a class called TrafficLight and I would like to have a
I have a class MyClass, and I would like to override the method ToString()
I have a class in my asp.net proj, I would like to get access

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.