WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Is there an equivlent data type as the "struct" in C (https://forum.worldviz.com/showthread.php?t=3678)

Zhi 04-02-2011 09:20 AM

Is there an equivlent data type as the "struct" in C
 
Hi

I want to create a "struct" type variable array in Vizard. Each element in the array contains 5 sub-elements with different data type (i.e. string, int, float, etc.). Any suggestion? Thanks

Zhi

Zhi 04-02-2011 01:38 PM

I checked the Python website. It seems a similar structure to the "struct" in C would be the "list" or "dict". The "list" is more like an array in C, while the "dict" is similar to the "struct". However, I don't know how to combine the list and dict to make a struct array. Can anyone help me?

Zhi

farshizzo 04-02-2011 01:56 PM

It sounds like you just want an array of custom class objects. The following code shows how to create a simple class and add instances of it to a list:
Code:

class MyStruct(object):
    def __init__(self,my_int,my_float,my_string):
        self.my_int = my_int
        self.my_float = my_float
        self.my_string = my_string

array = []
array.append( MyStruct(0,0.0,'foo') )
array.append( MyStruct(1,1.0,'bar') )

print array[0].my_string

Let me know if this isn't what you are looking for.

Zhi 04-02-2011 03:40 PM

That's exactly what I want. Thank you.

Zhi


All times are GMT -7. The time now is 11:14 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC