Python Forum
Difference between self and a reference to own class. (unique instance)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Difference between self and a reference to own class. (unique instance)
#1
class external(threading.Thread):
    i = 0
    def __init__(self, dir_q, result_q):
        super(external, self).__init__()
then right after "super", I write:
    self.i = 5
--external.i returns 0 (from another object)
    external.i = 5
--external.i returns 5 (from another object)

What is the difference, if only one instance of external exists?

By the way, self.i returns 5 if executed inside of a method from this instance in either way. If the instances sees self.i equal to external.i, why do other classes see external.i different that what this sees as self.i?
Reply


Messages In This Thread
Difference between self and a reference to own class. (unique instance) - by Dupletor - Oct-31-2018, 08:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  can Inner Class reference the Outer Class's static variable? raykuan 6 5,991 Jul-01-2022, 06:34 AM
Last Post: SharonDutton
  Access instance of a class Pavel_47 5 2,132 Nov-19-2021, 10:05 AM
Last Post: Gribouillis
Exclamation win32com: How to pass a reference object into a COM server class Alfalfa 3 4,937 Jul-26-2021, 06:25 PM
Last Post: Alfalfa
  Class Instance angus1964 4 2,485 Jun-22-2021, 08:50 AM
Last Post: angus1964
  Can we access instance variable of parent class in child class using inheritance akdube 3 14,030 Nov-13-2020, 03:43 AM
Last Post: SalsaBeanDip
  Pass by object reference when does it behave like pass by value or reference? mczarnek 2 2,580 Sep-07-2020, 08:02 AM
Last Post: perfringo
  Issue referencing new instance from other class nanok66 3 2,250 Jul-31-2020, 02:07 AM
Last Post: nanok66
  Class variable / instance variable ifigazsi 9 4,374 Jul-28-2020, 11:40 AM
Last Post: buran
  Python complains that class instance is not defined colt 3 5,694 Sep-17-2019, 12:32 AM
Last Post: ichabod801
  how to add class instance attributes from list 999masks 2 2,756 Jul-22-2019, 07:59 AM
Last Post: 999masks

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020