[SciPy-user] object-oriented help

Benjamin J. Racine bjracine@glosten....
Fri Nov 21 20:41:40 CST 2008


Hello all,

Please let me know if I should be posting just general OO stuff somewhere else, but I figure that this might be relevant to a lot of procedural programming types just jumping into python (and the example is straight out of FEA).  Anyways, I have the following code below.  The problem is, I need to be able to instantiate many nodes for a given element as well as many elements for a model.  Tackling this with built-ins such as arrays, lists and dicts seems straightforward, but I can't wrap my head around it in OO for some reason.  Do I just need to make my element and node inherit from a list and then use the ".append()" when I instantiate it?

Any help greatly appreciated.  Thanks,  Ben Racine


"""
untitled.py

Created by Ben Racine on 2008-11-21.
Copyright (c) 2008 __MyCompanyName__. All rights reserved.
"""

import sys
import os

class model(object):
    """docstring for model"""
    def __init__(self):
        pass
    class element(object):
        """docstring for element"""
        def __init__(self):
            pass
        elementID = 'something'
        elementPressure = 'something else'
        nodeCount = 'something else altogether'
        class node(object):
            """docstring for node"""
            def __init__(self):  
                pass
            nodeID = '1'
            x = 'xx'
            y = 'yy'
            z = 'zz'

if __name__ == "__main__":
    test = model()         
                


More information about the SciPy-user mailing list