WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-02-2011, 09:20 AM
Zhi Zhi is offline
Member
 
Join Date: Mar 2011
Posts: 49
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
Reply With Quote
  #2  
Old 04-02-2011, 01:38 PM
Zhi Zhi is offline
Member
 
Join Date: Mar 2011
Posts: 49
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
Reply With Quote
  #3  
Old 04-02-2011, 01:56 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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.
Reply With Quote
  #4  
Old 04-02-2011, 03:40 PM
Zhi Zhi is offline
Member
 
Join Date: Mar 2011
Posts: 49
That's exactly what I want. Thank you.

Zhi
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
data lose psykoko Vizard 3 12-16-2010 08:08 PM
Use saved text file data as replay sources problem mizutani_jun Vizard 4 10-14-2010 04:49 PM
Using 5DT plug-in with the data coming through network... mcicek Vizard 1 05-18-2009 05:17 PM
Flagging the Data Elittdogg Vizard 5 04-11-2008 11:40 AM
tracking using quaternarion data jfreeman Vizard 2 06-01-2005 08:48 AM


All times are GMT -7. The time now is 03:44 PM.


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