Hello,
i am playing with classes… how can i change my script to see whats in my class?
# Phython-Standard- und DesignScript-Bibliotheken laden
import sys
import clr
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def myfunc(self):
return("Hello my name is " + self.name)
p2 = Person("John", 36)
p2.myfunc()
OUT = p2
KR
Andreas
@newshunhk ,
it works…
… how about this i get just numbers…
# Phython-Standard- und DesignScript-Bibliotheken laden
import sys
import clr
class Instance:
def __init__(self, Type, Parameter):
self.Type = Type
self.Parameter = Parameter
def __str__(self):
return(self.Type, self.Parameter)
i1 = Instance("EG-0001", "B_001")
OUT = i1
@newshunhk ,
how can i get a list (like x.Parameters) of my class ?
at the moment it is just a string…
return("{}".format(self.Type + " " + self.Parameter))
//0 Instance
//0 EG001
//1 B_001
KR
Andreas
you can make i1 to be a list
# Phython-Standard- und DesignScript-Bibliotheken laden
import sys
import clr
class Instance:
def __init__(self, Type, Parameter):
self.Type = Type
self.Parameter = Parameter
def __str__(self):
return("{0}, {1}".format(self.Type, self.Parameter))
i1 = []
i1.append(Instance(0, "B_001"))
i1.append(Instance(1, "B_002"))
OUT = i1
2 Likes
@newshunhk ,
i want just the index and string, without the integers, how do i fix that
how is it sorted is “0” = Type, “1” = Parameter ? is the append method like mapping each value to his variable?
KR
Andreas
using __dict__
attribute
import sys
import clr
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def myfunc(self):
return("Hello my name is " + self.name)
def GetAttributes(self):
return self.__dict__
p2 = Person("John", 36)
p2.myfunc()
OUT = p2, p2.GetAttributes()
4 Likes
@c.poupin ,
thats realy fine!
# Phython-Standard- und DesignScript-Bibliotheken laden
import sys
import clr
class Instance:
def __init__(self, Type, Parameter):
self.Type = Type
self.Parameter = Parameter
def __str__(self):
return("{0}, {1}".format(self.Type,self.Parameter))
def GetAttributes(self):
return self.__dict__
p1 = Instance("EG001", "B_001")
OUT = p1.GetAttributes()
i will try to at more attributes , thanks
KR
Andreas
1 Like