"literal" objects

John Roth newsgroups at jhrothjr.com
Wed Dec 24 14:11:50 CET 2003


"Moosebumps" <purely at unadulterated.nonsense> wrote in message
news:%QbGb.2109$1f6.732 at newssvr25.news.prodigy.com...
> I've googled all over for this but can't find an answer...
>
> I'm fairly new to Python, and wondering if you can just list a bunch of
> objects as data.  For example, in C you would just do something like this:
>
> struct
> {
>     int a;
>     float b;
> } mystruct;

[rest snipped]

As Francis Avila said in another response, why would you really
want to do this? However, if you do, there are a couple of
easy ways.

[untested code]
class someData:
    pass

a = someData()
a.__dict__.update({item1: "Hi", item2: "there"})

print "%s %s" % (a.item1, a.item2) --> "Hi there"

However, frankly it's easier (and much clearer) to
use a dictionary:

a = {}
a.update({item1: "Hi", item2: "there"})
print "%(item1)s %(item2)s" % a --> "Hi there"

HTH

John Roth


>
> thanks,
> MB
>
>






More information about the Python-list mailing list