Python Forum
function that run once for all objects
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function that run once for all objects
#3
I think you are asking if there is a way to automatically call a method ONLY for the first instance of a class. There is no such thing, but it is something you could write using a a class method to keep track

class Alpha():
	first = True

	def __init__(self):
		if self.__class__.first:
			print("I am first", self)
			self.__class__.first = False
		else:
			# Do not first stuff
			print("I am not", self)

[Alpha() for _ in range(3)]
.

If I am totally off base on my interpretation, write the python code to do what you want to do. Even if it doesn't work it is a good way to describe what you are thinking.
mr_byte31 likes this post
Reply


Messages In This Thread
RE: function that run once for all objects - by deanhystad - Sep-30-2021, 08:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  AWS Boto3 - objects function PythonDialer 0 94 Yesterday, 11:50 AM
Last Post: PythonDialer

Forum Jump:

User Panel Messages

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