[Tutor] subscript problem

Jimmy verma jim_938@hotmail.com
Tue Jun 3 14:22:10 2003


Actually it is not possible for me to write the whole code as it is too 
lengthy. I have formulated the section in which i am getting the problem so 
i have written the code for the problem i am having. It takes the form like 
this and give the error written after the code:


class AB:
    def __init__(self):
        self.n_p = None
        self.po = Vec()      # in c struct this is Vec* po
        self.con = []        # in c struct this is short* con


class Vec:
    def __init__(self):
        self.x = None
        self.y = None



def XYZ(out):
    n = 0
    out.con.append(5)
    last = out.con[n]     # say n to some int value, last is also integer
    v_start = out.po[last]


#now call the function

l = XYZ(AB())

File "<stdin>", line 103, in ?
  File "<stdin>", line 98, in XYZ
AttributeError: Vec instance has no attribute '__getitem__'

I hope that i m able to express the problem.

thanks for giving consideration regarding my problem.

Regards;


>From: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
>To: Jimmy verma <jim_938@hotmail.com>
>CC: tutor@python.org
>Subject: Re: [Tutor] subscript problem
>Date: Tue, 3 Jun 2003 10:02:37 -0700 (PDT)
>
>
>
> > I am having a problem with handling some pointers. My problem is like
> > this:
> >
> > typedef struct ab
> > {
> >       short n_p;
> >       Vec* po;
> >        short* con;
> > } AB;
> >
> > typedef struct vec
> > {
> >       int x;
> >       int y;
> > } Vec;
>
>
>Hi Jimmy,
>
>
>Ok, all of the code you've shown at the moment is in C; I'll assume, for
>the moment, that you're trying to figure out how to do a translation of it
>into Python.
>
>
>
> > Now the function:
> >
> > XYZ(AB* out)
> > {
> >         last = out->con[n];            // last is of type int.
> >         lim = out ->po + last;        // lim is of type Vec.
> >
> >         v_start = out -> po[first];   // v_start is of type Vec.
> > }
> >
> >
> > The problem is that when i use po[first] it gives an error message
> > saying that
> >
> > AttributeError: Vec instance has no attribute '__getitem__'
>
>
>This is difficult to decipher, as you haven't shown us any Python code
>that implements your Vec vector class.  *grin*
>
>
>But you probably have a type problem: your structure 'ab' should contain a
>list of vectors, referred to by 'po'.  In C, a pointer to a structure can
>refer to a contiguous sequence of elements.
>
>The attribute error, though hints that the 'po' attribute isn't a list.
>But without seeing any code, we are really grasping at straws.
>
>
>
> > Can someone help me in sorting out the code for this in python.
>
>You have to show us your Python code first.  *grin*
>
>
>Good luck to you.
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

_________________________________________________________________
Watch Hallmark. Enjoy cool movies 
http://server1.msn.co.in/sp03/hallmark/index.asp Win hot prizes!