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

  • Home
  • SEARCH
  • 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 627525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:32:18+00:00 2026-05-13T19:32:18+00:00

I’ve been learning how to use Python for the better part of today after

  • 0

I’ve been learning how to use Python for the better part of today after giving up on an ugly bash script.

I’m trying to use 2 classes to define a few arrays of objects in which to store some unique strings and integers (1-10). The objects will consist of the following:

object[i].user
         .n     # n = i
         .name
         .coords
         .hero

(param1, param2, param3) will be different for each object.n and object.user, so I’m trying to use an assignment method that doesn’t look like garbage after writing 90 unique strings. Nesting an example I found didn’t work, so here’s the compromise:

class CityBean:
    def __init__(self,name,coords,hero):
        self.name = name
        self.coords = coords
        self.hero = hero

class Castles:
    def __init__(self,user,n):
        self.user = user
        self.n = n
        if self.user == 'user1':
            temp = {
                1:  CityBean( "name1"  , "coord1" , "hero1"),
                ... blah blah blah
                10: CityBean( "name10" , "coord10" , "hero10" )}[self.n]()
        if self.user == 'user2':
            temp = {
                1:  CityBean( "name11" , "coord11" , "hero11" ),
                ... blah blah blah
                10: CityBean( "name20" , "coord20" , "hero20" ) }[self.n]()
        if self.user == 'user3':
            temp = {
                1:  CityBean( "name21" , "coord21" , "hero21" ),
                ... blah blah blah
                10: CityBean( "name30" , "coord30" , "hero30" ) }[self.n]()
        self.name = temp.name
        self.coords = temp.coords
        self.hero = temp.coords
        __del__(temp)

I call it with something like this:

cities = list( Castles("user2",i) for i in range(1,11) )

It gives me this error:

AttributeError: CityBean instance has no __call__ method

And it blames this line:

                10: CityBean( "name20" , "coord20" , "hero20" ) }[self.n]() # pseudo
                10: CityBean( "" , "" , "" ) }[self.n]() # what is actually looks like

What’s wrong with my cruddy classes? I’m doing something retarded, aren’t I?

  • 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-13T19:32:18+00:00Added an answer on May 13, 2026 at 7:32 pm

    It’s really hard to guess what you want from what you provided, since, instead of saying what you want to do, you provided your newbie code, so one has a hard guess time.

    I’d think something like this would do:

    data = {
            (1, 'user1'): ("name1", "coord1", "hero1"),
            (2, 'user1'): ("name2", "coord2", "hero2"),
            #...
            (1, 'user2'): ("name11", "coord11", "hero11"),
            (2, 'user2'): ("name12", "coord12", "hero12"),
            # ...
        }
    
    
    class CityBean:
        def __init__(self,name,coords,hero):
            self.name = name
            self.coords = coords
            self.hero = hero
    
    class Castles:
        def __init__(self,user,n):
            self.user = user
            self.n = n
            name, coords, hero = data.get((n, user))
            self.citybean = CityBean(name, coords, hero)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.