FAQ
Howdy,

I have;

class System:
def __init__(self):
self.cg = Cg()
self.weight = 0

class Cg:
def __init__(self, x = 0, y = 0, z = 0):
self.x = x
self.y = y
self.z = z
def __repr__(self):
return str(self.x) + ", " + str(self.y) + ", " + str(self.z)

User can use this like;
block=System()
block.cg.x=5
block.cg
5, 0, 0

Q1
Now, how can I let the user of my System class set the cg values as either

block.cg.x=5
block.cg.y=6
block.cg.z=7.5

or

block.cg = [5, 6, 7.5] # so that block.cg[0] = block.cg.x

Q2
Is there a way to specify the cg.x, cg.y and cg.z without having to create a
Cg class first? Something similar to this:

class System:
def __init__(self):
self.cg.x = 0
self.cg.y = 0
self.cg.z = 0
self.weight = 0

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 9, '01 at 7:08p
activeAug 9, '01 at 7:08p
posts1
users1
websitepython.org

1 user in discussion

F Basegmez: 1 post

People

Translate

site design / logo © 2022 Grokbase