Python Forum
How I can create reference to member of the class instance?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How I can create reference to member of the class instance?
#6
What you want is not possible because one cannot overload or override the assignment operator in python. The semantics of
ref = 2
is to update the locals dictionary (or the globals dictionary) to have the key 'ref' point to the value 2. Note that the meaning of the statement is purely symbolic. The word 'ref' is used but not any operation that you have done before with it. That's why Python's documentation often uses 'name' instead of 'variable'. A variable in python is nothing but a word.

You could have either another attribute assignment or a function call to mean set self.data to value 2 because attribute assignment can be overriden
r.f = 2
ref(2)
However this will slow down the execution because direct attribute access is fast.
Reply


Messages In This Thread
RE: How I can create reference to member of the class instance? - by Gribouillis - Dec-04-2018, 02:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How does this code create a class? Pedroski55 6 759 Apr-21-2024, 06:15 AM
Last Post: Gribouillis
  Class member become static Quasar999 1 787 Sep-16-2023, 12:52 PM
Last Post: deanhystad
  can Inner Class reference the Outer Class's static variable? raykuan 6 6,339 Jul-01-2022, 06:34 AM
Last Post: SharonDutton
  Cannot convert the series to <class 'int'> when trying to create new dataframe column Mark17 3 8,840 Jan-20-2022, 05:15 PM
Last Post: deanhystad
  labels.append(self.classes.index(member.find('name').text)) hobbyist 1 2,037 Dec-15-2021, 01:53 PM
Last Post: deanhystad
  Access instance of a class Pavel_47 5 2,249 Nov-19-2021, 10:05 AM
Last Post: Gribouillis
Exclamation win32com: How to pass a reference object into a COM server class Alfalfa 3 5,129 Jul-26-2021, 06:25 PM
Last Post: Alfalfa
  Class Instance angus1964 4 2,588 Jun-22-2021, 08:50 AM
Last Post: angus1964
  Create Generator in the Class quest 1 2,241 Apr-15-2021, 03:30 PM
Last Post: jefsummers
  How to define a variable in Python that points to or is a reference to a list member JeffDelmas 4 2,838 Feb-28-2021, 10:38 PM
Last Post: JeffDelmas

Forum Jump:

User Panel Messages

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