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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:12:35+00:00 2026-05-28T01:12:35+00:00

When I run this code in the command prompt, the Person I create is

  • 0

When I run this code in the command prompt, the Person I create is automatically deleted, but when in IDLE the deletion does not occur. Why?

NOTE: This is a program that is supposed to create an address book (a list of dictionaries)

Here is my code:
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):
        bookEntry.__init__(self)
        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(self)

I run the code with a startup function:

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 the code is run in IDLE I receive the following prompts, and submit the following answers:

'''
    Hello! Would you like to add an entry or retrieve one?add
    Would you like to add a person or a company?person
    Please enter this persons name:Pig
    Please enter this persons email address:pig@brickhouse.com
    Please enter this persons phone number:333-333-3333
    Please add any notes if applicable:one of three
    Pig has been created
'''

Here, Pig is created and is not deleted. But in cmd…..

'''
    Hello! Would you like to add an entry or retrieve one?add
    Would you like to add a person or a company?person
    Please enter this persons name:Pig
    Please enter this persons email address:pig@brickhouse.com
    Please enter this persons phone number:333-333-3333
    Please add any notes if applicable:one of three
    Pig has been created
    Pig has been deleted
'''

Why is Pig being deleted?? __del__ is never called…

  • 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-28T01:12:35+00:00Added an answer on May 28, 2026 at 1:12 am

    When the program ends, all variables are automatically deleted (otherwise, there would be a memory leak). IDLE keeps the environment open so you can keep using the variables you’ve created.

    Note: My original answer was mistaken- I missed the lines

    list = []
    

    and

    list.append(self)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this will sound silly but i am executing my code from command prompt and
When I run this code the selected item is not visible. I've already tried
When I run this in my Windows command prompt it opens the default browser
When I run the following code below in a command prompt (as administrator): C:\Program
When i run the following command in the visual studio command prompt: D:\Documents\DEV\SARPilot\Docs\eoschema\schema\OrderSchema>svcutil /t:code
I compile this code, it has no error. But when run the EXE in
when I run this command ffmpeg -i C:\user\test.wmv >C:\user\test.wmv_info.txt 2>&1 from command prompt it
Why this code don't work,when i want run this code vwd 2008 express show
when i run this code : CONADefinitions.CONAPI_FOLDER_INFO2 FolderInfo; int iResult = 0; IntPtr Buffer
When I run this code, About half-way through the concatenation loop, $xml becomes null

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.