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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:20:30+00:00 2026-05-26T03:20:30+00:00

Let’s say I have a class called Map, and Map is constructed with argument

  • 0

Let’s say I have a class called “Map”, and Map is constructed with argument “country”. When instantiated Map should create a number of object of class “City”, based upon a list of city names for country. But how do I name the “city” objects?

pseudocode:

class Map(object):
    def __init__(self, country):
        for i in range(len(citynames)):
            cityname_i = City(i)

In words: so let’s say I have list of citynames: [“Boston”, “Chicago”, “Denver]. When I then do something like

us_map = Map(america)

I would like Map to create three instances of class City (defined elsewhere), named “Boston”, “Chigago” and “Denver”.

I am new to this, so maybe I got my glossary OOP glossary mixed up. If so please correct me.

Edit

It seems my example created som confusion. The way I see it, my question is not about dictionaries. I just used that as an example.

I am creating a game, were people can upload any number of scenarios. I don’t know how many scenarios they are uploading. But all scenarios basically work the same way, with a number of methods. So when I create ´game = Game(folder)´ my class should create an instance of class Scenario for each uploaded scenario file. Then a third class “Engine” plays through all the scenario’s…

But how do I assign names to the instances of “Scenario” automatically?

For the moment I am using ´glob´ to find the scenario files in the relevant folder. So I have those in a list, outside the class.

UPDATE:

It seems that either I have not made my question clear (can I create instances automatically on the fly) or that good people would rather point me in the right direction, than answer my foolish question. Anyway – I think that dictionary is the way to go. So for now I am closing this question (rplnt was the first to answer) and awarding the right answer to the first poster.

  • 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-26T03:20:31+00:00Added an answer on May 26, 2026 at 3:20 am

    Again, as in my previous answer, I would put the objects in a dictionary. Advantage over creating them in a namespace is that they will be easier to maintain. I.e. if you would create them like you said, you would still need to know about them, probably by remembering their reference stored in list (or perhaps dictionary?). If you would want to rely on the list of names, then your code would be full of try statements.

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

Sidebar

Related Questions

Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have an image called hello.png with dimensions 200x100 . I create
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have the following entity: public class Store { public List<Product> Products
Let's say I create an object like this: Person: NSString *name; NSString *phone; NSString
Let's say that I have classes like this: public class Parent { public int
Let's say I have a simple UserControl with no codebehind: <UserControl xmlns= .... x:Class=TrafficLight.LightControl>
Let's say I have the following models class Photo(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model):
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's say you create a wizard in an HTML form. One button goes back,

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.