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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:43:03+00:00 2026-05-17T20:43:03+00:00

I have written two scripts Write.py and Read.py . Write.py opens friends.txt in append

  • 0

I have written two scripts Write.py and Read.py.

Write.py opens friends.txt in append mode and takes input for name, email ,phone no and then dumps the dictionary into the file using pickle.dump() method and every thing works fine in this script.

Read.py opens friends.txt in read mode and then loads the contents into dictionary using pickle.load() method and displays the contents of dictionary.

The main problem is in Read.py script, it justs shows the old data, it never shows the appended data ?

Write.py

#!/usr/bin/python

import pickle

ans = "y"
friends={}
file = open("friends.txt", "a")
while ans == "y":
    name = raw_input("Enter name : ")
    email = raw_input("Enter email : ")
    phone = raw_input("Enter Phone no : ")

    friends[name] = {"Name": name, "Email": email, "Phone": phone}

    ans = raw_input("Do you want to add another record (y/n) ? :")

pickle.dump(friends, file)
file.close()

Read.py

#!/usr/bin/py

import pickle

file = open("friends.txt", "r")

friend = pickle.load(file)

file.close()

for person in friend:
    print friend[person]["Name"], "\t", friend[person]["Email"] , "\t", friend[person]["Phone"]

What must be the problem, the code looks fine. Can some one point me in the right direction ?

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-17T20:43:03+00:00Added an answer on May 17, 2026 at 8:43 pm

    You have to load from the file several times. Each writing process ignores the others, so it creates a solid block of data independent from the others in the file. If you read it afterwards, it reads only one block at a time. So you could try:

    import pickle
    
    friend = {}
    with open('friends.txt') as f:
        while 1:
            try:
                friend.update(pickle.load(f))
            except EOFError:
                break # no more data in the file
    
    for person in friend.values():
        print '{Name}\t{Email}\t{Phone}'.format(**person)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two (UNIX) programs A and B that read and write from stdin/stdout.
I have two applications written in Java that communicate with each other using XML
Suppose I have two applications written in C#. The first is a third party
Here's the thing: I have two applications, written in C++ and running on two
Hypothetically, you have two products, one written in Java, the other in C#. You
I have written a ruby script which opens up dlink admin page in firefox
I have written an AIR Application that downloads videos and documents from a server.
I have written some code in my VB.NET application to send an HTML e-mail
I have written a site in Prototype but want to switch to jQuery. Any
I have written an AppleScript which when supplied with a Windows network link, will

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.