Heh, yet another questoinf rom me :)

Aahz Maruch aahz at netcom.com
Sat Mar 25 16:36:19 CET 2000


In article <20000325033432.16207.cpmta at c000.sfo.cp.net>,
Falknor  <falknor at worldspy.net> wrote:
>
>What would be the best way to do something like this in python...
>
>struct blaat
>{
>int blaat2;
>char* blaat3;
>char blaat4;
>}
>
>struct blaat blaat_table[] =
>{
>    { 0, "lklj", 'c'},
>    { 5, "jkjj", 'a'}
>}
>
>i know you'd convert the struct over to a class.. IE:
>class blaat:
>    blaat2 = 0
>    blaat3 = ""
>    blaat4 = ""

Actually, that should be

class blaat:
  def __init__ ( self, blaat2=0 , blaat3='', blaat4=''):
    self.blaat2 = blaat2
    self.blaat3 = blaat3
    self.blaat4 = blaat4

blaat_list = [ blaat(0,"foo",'c'), blaat(5,"bar",'a') ]

You might also consider using a dictionary if you want key-based access
to the data:

blaat_dict = [ 'x': blaat(0,"foo",'c'), 'y': blaat(5,"bar",'a') ]
print blaat_dict['x']
--
                      --- Aahz (Copyright 2000 by aahz at netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

Usenet is not a democracy.  It is a weird cross between an anarchy 
and a dictatorship.  --Aahz



More information about the Python-list mailing list