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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:09:06+00:00 2026-05-31T20:09:06+00:00

I have several classes, and want to work with their collections like with a

  • 0

I have several classes, and want to work with their collections like with a DB (or Django ORM, but simpler). Working with a DB would be a huge overhead, so I’d prefer having similar functionality in memory:

>>> node = Nodes.create(lat=X,lon=Y)
>>> node.id
1

>>> Nodes.all()
[<Node 1>]

>>> Nodes[1]  # by id
[<Node 1>]

>>> way_nodes = map(Nodes.create, ((X, Y), (Z, W)))
>>> way = Ways.create(way_nodes)
>>> way.nodes
[<Node 2>, <Node 3>]

>>> way.id
1

This is basically all what I need. Is there anything similar in Python or in custom packages?

If none, and I have to write my own, what’s the best choice to inherit from?

  • 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-31T20:09:07+00:00Added an answer on May 31, 2026 at 8:09 pm

    Those seem like pretty basic requirements, why not code them into your classes?

    from itertools import count, starmap
    
    class Node(object):
        nextid = count(1).next
        nodes = {}
        def __init__(self, lat, lon):
            self.lat, self.lon = lat, lon
            self.id = self.nextid()
            self.nodes[self.id] = self
    
        @classmethod
        def all(cls):
            return cls.nodes.values()
    
        def __repr__(self):
            return '<Node %s>' % self.id
    
        @classmethod
        def byid(cls, id):
            return cls.nodes[id]
    
    class Way(object):
        nextid = count(1).next
        def __init__(self, nodes):
            self.nodes = nodes[:]
            self.id = self.nextid()
    
    node = Node(lat='X',lon='Y')
    print node.id
    print Node.all()
    print Node.byid(1)
    
    way_nodes = list(starmap(Node, (('X', 'Y'), ('Z', 'W'))))
    way = Way(way_nodes)
    print way.nodes
    print way.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a hierarchical JPA mapping that is several Classes deep. Something like this
I want to have several data classes which all have an identifier that is
I have several specific repository classes and I want to share the same db
i have several classes with members called 'Id'. Originally i wanted to store these
I have several classes, that all derives from SuperClass. When the classes are created,
I have several classes such as Order, Customer, etc. These classes serve for holding
I have several classes each containing several methods annotated with @Test . The classes
This is for a web project so i have several classes that inherit from
I have several small classes that are in a single file in /app/models, similar
I've worked out most of the code and have several game classes. The one

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.