Python Forum
Object Oriented programming (OOP) problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Object Oriented programming (OOP) problem
#6
(May-31-2021, 12:32 PM)BashBedlam Wrote: Your function is not returning anything. Try it like this:

#Create arbitrary class
class Object():
	def __init__(self,value1,value2,value3):
		self.v1=value1
		self.v2=value2
		self.v3=value3

#Create an arbitrary object
D=Object(2,3,"abc")

#Function to create a new object based on the previous
def new_object(A):
	#Here we get keys
	a=[]
	a=list(A.__dict__.keys())

	for i in range(len(a)):
		if type(getattr(A, a[i])) != int:
			delattr(A, a[i])
			print(A.__dict__.keys())
	return Object (a[0], a[1], 0)

#New object
Z=new_object(D)
print (type (Z))

Thank you very much
Reply


Messages In This Thread
RE: Object Oriented programming (OOP) problem - by OmegaRed94 - May-31-2021, 07:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Can someone help me solve this programming problem? SuchUmami 6 1,025 Nov-20-2023, 10:01 AM
Last Post: EdwardMatthew
Question Linear Programming Problem Axel_LF 0 775 Feb-23-2023, 11:03 PM
Last Post: Axel_LF
  python 3 raspberry pi 4 dual control motor programming problem yome 0 2,032 Mar-21-2021, 05:17 PM
Last Post: yome
  Basic programming problem darek88 1 2,054 Sep-30-2019, 01:13 PM
Last Post: ichabod801
  Please help! Problem with my Point object itrema 2 5,322 Mar-05-2019, 09:57 AM
Last Post: itrema
  Object Oriented Programming jackbk 8 4,563 Aug-24-2018, 01:13 PM
Last Post: Windspar
  Object Oriented DB Interactions datasundae 2 2,436 May-25-2018, 09:51 PM
Last Post: datasundae
  Oriented Object ldthan 1 2,480 Mar-27-2018, 11:26 AM
Last Post: Larz60+
  problem with "hiding" object league55 4 3,292 Jan-16-2018, 11:21 PM
Last Post: league55

Forum Jump:

User Panel Messages

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