[FRPythoneers] Object instantiation (newbie question)

Ken Kinder kkinder at tridog.com
Wed Aug 1 19:23:55 MDT 2001


Yes, since you are accessing elements in a dictionary through a sequence
of numbers anyway, a list would make more sense.

Sean Reifschneider wrote:
> 
> You don't want to make the objects "in the clear".  Remember, that even if
> you were to do this, you'd be effectively instantiating them in a
> dictionary anyway, because the symbols that are stored "in the clear" are
> stored as part of a name-space dictionary by the Python interpreter.
> 
> Also, a dictionary may not be the best way to do it, but you certainly
> could go that way.  Using an integer key for a dictionary is a bit odd
> though.  Here are some alternatives:
> 
>    for player in range(num_players):
>       name = get_name()
>       player_dict[name] = Hand(player_dict(name))
> 
> or:
> 
>    player_list = []
>    for player in range(num_players):
>       player_list.append(Hand(get_name()))
> 
> Using a list is probably better for using integer-keyed items, because you
> can implement a turn as:
> 
>    for player in player_list:
>       print 'Your turn,', player.name
> 
> Sean
> --
>  "If life was fair, Elvis would be alive and all the impersonators would
>  be dead."  -- Johnny Carson
> Sean Reifschneider, Inimitably Superfluous <jafo at tummy.com>
> tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python
> _______________________________________________
> This message sent by the FRPythoneers mailing list.
> Unsubscribe: echo unsubscribe | FRPythoneers-request at lists.community.tummy.com
> URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers



More information about the FRPythoneers mailing list