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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:01:20+00:00 2026-05-24T08:01:20+00:00

I’d like to define the contents of a large dictionary object up between files.

  • 0

I’d like to define the contents of a large dictionary object up between files. I’m wondering if this is possible in python.

Ideally, this is what I’d like to do:

Main File: (dict_object_main.py)

# File name: dict_object_main.py

import dict_object_sub1
import dict_object_sub2

dict_object = {}

def doSomeStuffWithTheDictObject:
    ...
    return

1st File that adds a lot of stuff to “dict_object”: (dict_object_sub1.py)

# File name: dict_object_sub1.py
from dict_object_main import dict_object

dict_object['sub1'] ={
     'property1':'value1'
    ...
    ,'property9999':'value9999'
}

2nd File that adds a lot of stuff to “dict_object”: (dict_object_sub2.py)

# File name: dict_object_sub2.py

from dict_object_main import dict_object

dict_object['sub2'] ={
     'property1':'value1'
    ...
    ,'property9999':'value9999'
}

I have something similar set up in javascript. Is it ok to do it this way in Python or should I be doing it differently?

Thanks!

  • 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-24T08:01:21+00:00Added an answer on May 24, 2026 at 8:01 am

    You may want to use the update method instead.

    # Same for dict_object_sub1.py or dict_object_sub2.py
    
    from dict_object_main import dict_object
    dict_object.update({
        'prop1': 'val1',
        # ...
    })
    

    Note:
    I don’t think it makes much sense to split the declaration out on two different files. The final memory occupied by the dictionary will be exactly the same in both cases.

    Edit:
    As daveydave400 pointed out in his answer, the importing order is wrong too.

    You need at least 3 distinct files (or doing the updates in the importing module):

    • A dict_declare.py file, where you declare your dictionary:

      dict_object = {}
      
    • A file for each partial dictionary declaration:

      from dict_object import dict_object
      
      dict_object.update({
          'prop1': 'val1',
          # ...
      })
      
    • Your main file:

      from dict_declare import dict_object
      import dict_object_sub<n>
      # ... repeat
      
      def doSomeStuffWithTheDictObject:
          ...
          return
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I have some data like this: 1 2 3 4 5 9 2 6
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words

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.