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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:08:57+00:00 2026-05-29T04:08:57+00:00

I am currently learning python programming (and am a beginner at it). Currently I

  • 0

I am currently learning python programming (and am a beginner at it). Currently I am stuck on files exercises (so these are set things I need to do, rather than doing whatever I want. Unfortunately, it also means I probably can’t do any complicated (for me) shortcuts)

Currently using Python 3.2.2

I need two different programs. One is to input what the user types in (a name and a DOB) and put that into records in a list and write that into a binary file. The other is to read that file and print that into a table using padding.

Codes:

First

    import pickle

class newperson():
    def __init__(self):
        self.name = ""
        self.dob = ""

stop = False
people = []
print("When you want to stop just hit enter")
count = 0

while stop == False:
    name = input("Please Enter the name: ")
    if len(name) == 0:
        stop = True
    else:
        people.append(newperson())
        people[count].name = name
        people[count].dob = input("Please enter their DOB: ")
        count = count + 1

file = open("ex9.4.dat", "wb")
pickle.dump(people,file)
file.close()

Second:

import pickle

myfile = open("ex9.4.dat", "rb")

people = pickle.load(myfile)

print("{0:<15}{1}".format("Name","DOB"))
for item in people:
    print("{0:<15}{1}".format(item.name,item.dob))

The problem is that I am getting the following error when trying to run the 2nd program:

AttributeError: 'module' object has no attribute 'newperson'

on

    people = pickle.load(myfile)

Unfortunately, when I have looked for answers on the other questions, either none of the solutions have worked, don’t apply to me or mostly just went WAAAY over my head.

What am I doing wrong?

Thanks in advance for the help.

  • 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-29T04:08:58+00:00Added an answer on May 29, 2026 at 4:08 am

    When pickle loads the file it tries to creates newperson instances, but newpersonis not defined in the second program. To solve that problem, you could create a new file newperson.py just containing the definition of the class `newperson.py“

    # newperson.py
    class newperson():
        def __init__(self):
            self.name = ""
            self.dob = ""
    

    In both programs, import the class after the import or pickle:

    from newperson import newperson
    

    Alternatively, you could use a dictionary instead of the newperson class.

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

Sidebar

Related Questions

I'm a young (highschool next year) beginner programmer, currently learning Python and starting to
I currently use Python for most of my programming, but I'm interested in learning
I'm currently learning python from a book called 'Python for the absolute beginner (third
im currently learning python (in the very begining), so I still have some doubts
I'm currently learning Python using Zelle's Introductory text, and I'm trying to recreate one
I'm currently learning on how to use the Python optparse module. I'm trying the
I'm a hobbyist programmer with a fair grasp of Python and I'm currently learning
I'm currently learning Haskell, Which language (F# or Haskell) do you prefer for programming
I am currently learning python in preperation for a class over the summer and
I am learning Python (I have a C/C++ background). I need to write something

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.