Expression problem.

Nethirlon . nethirlon at gmail.com
Wed Oct 6 07:33:31 EDT 2010


On 6 okt, 11:53, Peter Otten <__pete... at web.de> wrote:
> Sebastiaan de Haan wrote:
> > Thank you Chris,
>
> > I'll try and find the attribute in the code. That was my conclusion
> > aswell... The original author must have defined it somewhere...
>
> Don't forget to check whether the object's class (or any of its bases) has a
> __getattr__() or __getattribute__() method.
>
> >>> class A(object):
>
> ...     def __getattr__(self, name):
> ...             return 42
> ...>>> a = A()
> >>> a.as
>
>   File "<stdin>", line 1
>     a.as
>        ^
> SyntaxError: invalid syntax
>
> Note tha you can still access such an attribute using getattr()
>
> >>> getattr(a, "as")
>
> 42
>
> Peter

Thank you Peter,

While searching the document I found the following code:

class Open(dpkt.Packet):
        __hdr__ = (
            ('v', 'B', 4),
            ('as', 'H', 0),
            ('holdtime', 'H', 0),
            ('identifier', 'I', 0),
            ('param_len', 'B', 0)
            )

So, I am new at programming with Python, but doing my best to grasp
the concept here. From what I am understanding is that the __hdr__ is
something that the original programmer cameup with for him self. I am
just curious as to weather the "as" in this piece of code is the one I
am searching for.

Thanks in advance.



More information about the Python-list mailing list