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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:52:19+00:00 2026-06-07T21:52:19+00:00

Not a specific coding question so much as program structure in general. I’m one

  • 0

Not a specific coding question so much as program structure in general.

I’m one of those poorly self taught hobby programmers and I’ve got no idea what the best route is here. I want to create an object with 4 variables (name, objID, a, and b). For example:

class myObj:
    def __init__(self, objName, objID):
        self.name = objName
        self.objID = objID
        self.a = 0
        self.b = 0

My question/problem is I want the initial values for a and b to be pulled from a .txt file, based on the value of objID. I actually want more than just 2 variables, and I’ll be creating hundreds of these objects with a dozen different types.

I don’t think I want to read the file from this class, as I believe it will reopen the file every time an object is created, and I don’t really like pulling it into a list/array/dictionary and passing it to the class because the myObj class will only be called from an object above it, also with dozens of instances.

To clarify – I plan to create 100 ‘topObj’ objects, each with 5-10 ‘myObj’ objects, with each ‘myObj’ having starting values (that will change later), pulled from a text file, and I don’t know when and where to read the data from the text file without reading it 500-1000 times.

Hopefully this makes some semblance of sense.

Thanks,
db_

  • 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-07T21:52:21+00:00Added an answer on June 7, 2026 at 9:52 pm

    I don’t think I want to read the file from this class,

    Probably not since the class represents one entry and so you’d have to search the entire file for it on each entry, as you said.

    and I don’t really like pulling it into a list/array/dictionary and passing it to the class because the myObj class will only be called from an object above it, also with dozens of instances.

    You don’t have to store it in the instance, if you don’t like that.

    Just read the entire file into a dictionary and pass it where you need it. It’s not like it’s cloning the dictionary each time.

    topObj then can give all the myObj constructors that dictionary. It’s always the same dictionary anyhow, I don’t get what’s supposedly bad about it, quite the opposite: it’s explicit and so it’s the Python way.

    You probably need some way of quickly finding entries and that’s how you can do that.

    pulled from a text file

    From just one text file, independent of the topObjs? Then read the contents of the text file into a dictionary and pass that (you can put that into a load function to have it tidy if you want that).

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

Sidebar

Related Questions

Not a specific code question, but more of a general coding question. I'm trying
This is a general question. And may not be specific to datagrids. How can
My question is not about a specific code snippet but more general, so please
I'm here not with a question of specific coding, but more of a query
This is more of a general question rather than a specific problem. I'm coding
This is not a question on specific technical coding aspect of MPI. I am
...meaning pattern in its general English usage, not specific to OO design patterns. Given
This is not a specific question but a generic question which was in my
I have a question about whether or not a specific way of applying of
I have seen a few posts regarding this issue but not one specific to

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.