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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:19:57+00:00 2026-05-31T12:19:57+00:00

im getting this exception in Python, Exception AttributeError: ‘NoneType’ object has no attribute ‘population’

  • 0

im getting this exception in Python,

Exception AttributeError: "'NoneType' object has no attribute 'population'" in del of <main.Robot instance at 0x104eb7098>> ignored

this is my code,

class Robot:

    population = 0 #class variable, number of robots

    def __init__(self, name):

        self.name = name
        print ('(initializing {0})'.format(self.name))

        Robot.population += 1

    def __del__(self):
        print('{0} is being destroyed!'.format(self.name))
        Robot.population -= 1

        if Robot.population == 0:
            print ('{0} was the last one.'.format(self.name))
        else:
            print('there are still {0:d} robots working.'.format(Robot.population))

    def sayHi(self):
        print('hole mi mestre me llama {0}'.format(self.name))

    def howMany():
        print('hay {0:d} robots'.format(Robot.population))
    howMany = staticmethod (howMany)


#instantiate 2 robots
mingos = Robot('alvergas')
mingos.sayHi()
Robot.howMany()

pingos = Robot('chupacabra')
pingos.sayHi()
Robot.howMany()

#destroy one
del mingos

Robot.howMany()

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-31T12:19:59+00:00Added an answer on May 31, 2026 at 12:19 pm

    I changed the code to run on Python 2.7 and added some prints, here’s the result:

    # So I changed the code as follows:
    
        class Robot:
    
            population = 0 #class variable, number of robots
    
            def __init__(self, name):
    
                self.name = name
                print '(initializing %s)' % self.name
    
                Robot.population += 1
    
            def __del__(self):
                print'%s is being destroyed!' % self.name
                print 'pre1 %s type %s' % (Robot, type(Robot))
                Robot.population -= 1
    
                print 'pre2'
                if Robot.population == 0:
                    print '%s was the last one.' % self.name
                else:
                    print 'there are still %d robots working.' % Robot.population
    
            def sayHi(self):
                print '%s says hi' % self.name
    
            def howMany():
                print 'there are %d robots' % Robot.population
            howMany = staticmethod(howMany)
    
    
        #instantiate 2 robots
        mingos = Robot('alvergas')
        mingos.sayHi()
        Robot.howMany()
        print 'end program'
    
    # and the output is:
    
        (initializing alvergas)
        alvergas says hi
        there are 1 robots
        end prog
        alvergas is being destroyed!
        pre1 None type <type 'NoneType'>
        Exception AttributeError: "'NoneType' object has no attribute 'population'" in
        <bound method Robot.__del__ of <__main__.Robot instance at 0x0223C918>> ignored
    

    So the exception occurs after the program ends.
    As __del__ description says: “when __del__() is invoked in response to a module being deleted (e.g., when execution of the program is done), other globals referenced by the __del__() method may already have been deleted or in the process of being torn down (e.g. the import machinery shutting down).”

    I think that in your case the line Robot.population -= 1 is called when the class Robot has already been torn down, becoming None. Trying to access an attribute of None causes an exception.

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

Sidebar

Related Questions

This has been driving me nuts. I keep getting the following exception System.InvalidOperationException: The
I'm getting errors like this: 2010-07-13 20:43:15.131 Python[1527:60f] main: Caught OC_PythonException: : LoginMenuSet instance
I am getting this exception while accessing the jax-ws web service from my client.
I'm trying to parse and load an XML document, however I'm getting this exception
This is the exception that I'm getting when I'm trying to bind to a
This is the exception that I am getting when I run my application with
I am getting Following Exception while configuring the Connection Pool in Tomcat This is
So I'm getting a prefetch abort exception on our arm9 system. This system does
Getting this error with jquery & jquery.form. Site has been live for awhile..upgraded to
Running Django Nonrel, with Google App Engine 2.6.0 and Python 2.7, I'm getting this

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.