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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:09:47+00:00 2026-05-28T04:09:47+00:00

I am writing a program to add to and update an address book. Here

  • 0

I am writing a program to add to and update an address book. Here is my code:

EDITED

import sys
import os

list = []

class bookEntry(dict):
    total = 0

    def __init__(self):
        bookEntry.total += 1
        self.d = {}

    def __del__(self):
        bookEntry.total -= 1
        list.remove(self)

class Person(bookEntry):
    def __init__(self, n):
        self.n = n
        print '%s has been created' % (self.n)

    def __del__(self):
        print '%s has been deleted' % (self.n)

    def addnewperson(self, n, e = '', ph = '', note = ''):
        self.d['name'] = n
        self.d['email'] = e
        self.d['phone'] = ph
        self.d['note'] = note

        list.append()

    def updateperson(self):
        key = raw_input('What else would you like to add to this person?')
        val = raw_input('Please add a value for %s' % (key))
        self.d[key] = val
def startup():
    aor = raw_input('Hello! Would you like to add an entry or retrieve one?')
    if aor == 'add':
        info = raw_input('Would you like to add a person or a company?')
        if info == 'person':
            n = raw_input('Please enter this persons name:')
            e = raw_input('Please enter this persons email address:')
            ph = raw_input('Please enter this persons phone number:')
            note = raw_input('Please add any notes if applicable:')

            X = Person(n)
            X.addnewperson(n, e, ph, note)
startup()

When I run this code I get the following error:

in addnewperson
    self.d['name'] = n
AttributeError: 'Person' object has no attribute 'd'

I have two questions:

UPDATED QUESTIONS
1. why isnt the d object being inherited from bookentry()?

I know this question/code is lengthy but I do not know where to go from here. Any help would be greatly appreciated.

  • 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-28T04:09:47+00:00Added an answer on May 28, 2026 at 4:09 am
    1. The addnewperson shoud have ‘self’ as first argument; actually, the name doesn’t matter (‘self’ is just a convention), but the first argument represent the object itself. In your case, it’s interpreting n as the “self” and the other 3 as regular arguments.

    2. ____del____ must not take arguments besides ‘self’.

    Edit: BTW I spotted a few other problems in your example, that maybe you’re not aware of:

    1) d in bookentry is a class member, not an instance member. It’s shared by all bookentry’s instances. To create an instance member, use:

    class bookentry(dict):
        def __init__(self,n):
            self.d = {}
            # rest of your constructor
    

    2) you’re trying to access d directly (as you would do in Java, C++ etc), but Python doesn’t support that. You must have a ‘self’ parameter in your methods, and access instance variables through it:

    class person(bookentry):
        def foo(self,bar):
           self.d[bar] = ...
    
    person().foo(bar)
    

    Update: for the last problem, the solution is to call the super constructor (which must be done explicitly in Python):

    class Person(bookEntry):
        def __init__(self, n):
            super(Person, self).__init__()
            self.n = n
            print '%s has been created' % (self.n)
    

    A brief explanation: for people with background in OO languages without multiple inheritance, it feels natural to expect the super type constructor to be called implicitly, automatically choosing the most suitable one if no one is mentioned explicitly. However, things get messy when a class can inherit from two or more at the same time, for this reason Python requires the programmer to make the choices himself: which superclass constructor to call first? Or at all?

    The behavior of constructors (and destructors) can vary wildly from language to language. If you have further questions about the life cycle of Python objects, a good place to start would be here, here and here.

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

Sidebar

Related Questions

I'd like to add video conversion capabilities to a program I'm writing. FFmpeg's command
I am writing a program to add a certain property to a column. Basically
I am currently writing a program which is having a lot of code duplication
I'm writing a program using the Managed WiFi API . Here's how I get
I have been writing some code that detects add and removal of USB devices,
I'm writing a one-time Java program to add a bunch of rows in a
They always talk about extendability and flexibility when writing code, but here I am
I'm a writing a program to add a new way of communication such as
I am doing a POC with the rabbitMQ and writing a program to add
Im writing a program that should read input via stdin, so I have the

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.