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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:00:40+00:00 2026-06-15T00:00:40+00:00

Some things do not work if I use __init__ instead of init__ in a

  • 0

Some things do not work if I use __init__ instead of init__ in a class. I am just curious what the difference between these two is.

Here is a piece of the class. But it really does not matter because it works with init__ and it doesn’t with __init__. I understand that it was a typing error, then it means that I can actually call it any way.

class Point(namedtuple('Point', 'x, y, z')):
  'class of a point as a tuple array'
  __slots__ = () # prevent creation of instance dictionaries to save memory

  def init__(self, x, y, z):
    self.x = x
    self.y = y
    self.z = z

  def __del__(self):
    'delete the Point'

  def __repr__(self):
    'Return a nicely formatted representation string'
    return '[%r, %r, %r]' % (self)

  def __str__(self):
    'printing format'
    return '%s[%r, %r, %r]' % (self.__class__.__name__,
                               self.x, self.y, self.z)

  def __add__(self, other):
    return Point(self.x + other.x, self.y + other.y, self.z + other.z)

  def __sub__(self, other):
    return Point(self.x - other.x, self.y - other.y, self.z - other.z)

  def __mul__(self, scal):
    'multiplication ny scalar'
    return Point(self.x * scal, self.y * scal, self.z * scal)

  def __div__(self, scal):
    'division ny scalar'
    if scal != 0.0:
        return Point(self.x / scal, self.y / scal, self.z / scal)
    else:
        sys.exit('Division by zero!')

My question there was “How to instantiate an object in two different ways?” and this way it works perfectly.

How to explain this?

  • 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-06-15T00:00:42+00:00Added an answer on June 15, 2026 at 12:00 am

    __init__ is the hook used to initialize your instance. (it is always called when you create an instance).

    init__ is just a class method with a wonky name.

    You need to show us your code; if something is broken when you have a method named __init__ you made a mistake there. Renaming it to init__ just means it won’t be called automatically, thus not triggering your coding mistake.

    In the comment you refer to, the author did use __init__ in his comment but forgot to escape the leading underscores, and they were interpreted as code to start bold text instead:

    __this is bold__
    

    becomes this is bold. Note that the trailing __ on __main__ also is lost in that comment.

    In your updated code, you are trying to override the __init__ method of a (subclass) of tuple, which is a special case. By renaming the __init__ method to init__ you created a different method and did not run into this common problem at all.

    See Subclassing Python tuple with multiple __init__ arguments for more detail on why this is a problem; you have to create a __new__ method instead. __new__ is the factory method to create instances, __init__ then initializes the data. But that doesn’t work on immutable types such as namedtuple or tuple, since you are not supposed to change the instance after the factory created it.

    In this specific case, you do not need an __init__ or a __new__ method at all because the namedtuple subclass Point already takes care of the initialization of the x, y and z attributes. By renaming __init__ to init__ you made things work, but you do end up with a pointless init__ method that you’ll never use. Just delete it.

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

Sidebar

Related Questions

Not sure if I've just missed something but this doesn't work: $(this).children('td.threadtitle a').html('thread title');
Not sure if im just being stupid or something but here goes i work
I am playing with Autolayout in Cocoa and some things are not clear for
I am not sure about some things in OOP. If I have Class1 ,
I'm trying something like this, but this example does not work. jsObj = {};
Am I not seeing something obvious here, can't seem to get this to work...
Can someone work out why my JScrollPane is not working. Perhaps something I may
I'm creating a PHP web application framework (MVC). I'd rather not use external libraries
I am trying to inject entity manager in some helper class, I can pass
In Python 3 one can use super() instead of super(MyClass, self) , but 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.