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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:22:37+00:00 2026-06-06T11:22:37+00:00

What I have is 3 dictionaries dumping with pickle to 3 different files. I

  • 0

What I have is 3 dictionaries dumping with pickle to 3 different files. I had originally just written a read and write function for each file so a total of 6 functions. So last night I tried to make it so I would only have to use 1 read function and 1 write function. I got the write function to work but the read function is not. I have been looking since last night for a solution to this problem and I am fed up so any help you can give I would appreciate.
I am new to programming/python if you could not tell. Here is the code I’m using:

w = {} # would be past in as source

def writing(filename, source): 
    with open(filename, 'wb') as st:
        pickle.dump(source, st)

def reading(filename, source):
    with open(filename, 'rb') as st:
        source = pickle.loads(st.read())

reading('test.txt', w)

The error I got is:

Traceback (most recent call last):
  File "./database.py", line 303, in <module>
   pw.check_pwd(p)
  File "./database.py", line 47, in check_pwd
    if self.pwds[self.user] == hashlib.sha512(self.pwd + self.salt).hexdigest():
KeyError: 'Codex' this was the error I was getting sorry for the bad post
  • 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-06T11:22:38+00:00Added an answer on June 6, 2026 at 11:22 am

    I do not know what problem you are trying, but I am very confident that you want the result of the unpickling in the global w variable, right? Well, you cannot do it this way: when you attribute a value to the source variable, you are updating only the local variable source but the variable w still points to the same value. Maybe this answer may help you to understand what is happening.

    There are various solutions to it. One of my favorite ones is the @katrielatex one: return the value:

    def reading(filename, source):
        with open(filename, 'rb') as st:
            source = pickle.loads(st.read())
        return source
    w = reading(filename, w)
    

    Actually, you do not even need the source parameter:

    def reading(filename):
        with open(filename, 'rb') as st:
            source = pickle.loads(st.read())
            return source
    
    w = reading(filename)
    

    Another solution is to update the dictionary pointed by source. In this case, no return is needed:

    def reading(filename, source):
        with open(filename, 'rb') as st:
            source.update(pickle.loads(st.read()))
    
    reading(filename, w)
    

    Also, you can make w a global variable inside the function (but it is the worst solution):

    def reading(filename):
        global w
        with open(filename, 'rb') as st:
            w = pickle.loads(st.read())
    
    reading(filename)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my problem: Lets say I have two dictionaries, dict_a and dict_b. Each of
I have information about a bunch of different items. Each item has its own
I have an array of dictionaries. Each dictionary is like this object, @myObject, [NSValue
I have a list of dictionaries. Each dictionary has a colour attribute. For example:
There are two dictionaries like this, two dictionaries have same keys but different values.
I have two dictionaries with a string key and different value types. private Dictionary<string,
I have two dictionaries of data and I created a function that acts as
I have a directories with filenames. I want for each of the files to
I have dictionaries. First I initialize them. public Dictionary<string, Bitmap> lookup; public Dictionary<string, Bitmap>
I have two dictionaries of the following structure: a) dict1 = {'a':[ [1,2], [3,4]

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.