[Tutor] objects becoming pointers

bob gailer bgailer at gmail.com
Wed Jul 15 17:41:29 CEST 2009


chris Hynes wrote:
> I guess I have to start somewhere to ask............
>
> I want the user to input a name, say "Chris". I know I can use the code:
>
> name=raw_input()
>
> I now want:
>
> "Chris"=zeros((3,3))

This is a FAQ. In Python one is discouraged from dynamically creating 
variable names. Preferred is a dictionary.

names = {} # empty dictionary
name=raw_input()
names[name]=zeroes((3,3))
print names["Chris"]

-- 
Bob Gailer
Chapel Hill NC
919-636-4239


More information about the Tutor mailing list