[Tutor] Fwd: How do you create built-in objects (dicts, lists, etc) without specifying {}, [], etc...

Kent Johnson kent37 at tds.net
Fri May 19 23:06:19 CEST 2006


Bill Carson wrote:
> Do you know how to create instances of dictionaries, lists, integers, 
> longs, etc without having to specify it in code...
>  
>  Instead of specifying: 
>         a={"bla":1}
>  or ...
>         a=[1,2,3]
>  
> Is there another way??

I'm not really sure what you are looking for here. You can use the type 
names to create new objects:
a = dict(bla=1)
or
a = dict()
a['bla'] = 1

a = list()
a.append(1)
a.append(2)
a.append(3)

> The "new" module does not appear to create built-in types, or am I wrong.
> I've read something about "type objects", but I don't know how to 
> instantiate them outside of specifying them as python syntax embedded in 
> code (see examples above).

If you could do what you want, what would it look like? (In other words, 
make up some syntax and show us.) Why do you want to do this?

Kent



More information about the Tutor mailing list