New to python

Paul Boddie paul at boddie.org.uk
Mon Nov 30 12:35:57 EST 2009


On 30 Nov, 18:14, inhahe <inh... at gmail.com> wrote:
> i don't think structs technically exist in Python (though they exist
> in C/C++), but you could always use a plain class like a struct, like
> this, for a simple example:
>
> class Blah:
>   pass
>
> b = blah()
> b.eyecolor = "brown"

[...]

Yes, a "bare" class can be instantiated and the attributes of the
created instance populated as desired. In fact, there are structures
(or "structs") provided by various built-in extensions supplied with
Python, such as the time structure (struct_time), although this
appears as a class if you try to investigate it more closely from the
Python prompt. See the Objects/structseq.c file in the Python source
distribution for how such structures are actually implemented,
however.

Paul



More information about the Python-list mailing list