Newbie help- Can multiple instances with multiple names automatically created.

Nav navjotmusic at gmail.com
Tue Jan 5 00:27:12 EST 2010


"> if yes then:
>   if using globalnamespace is bad then why does every book or tutorial
> about python classes give the above  style of assignment as an
> example?

That's a basic assignment example. It's not a direct manipulation of
globals(), like the solution given by Jan, which you seem to feel is
the answer. And unless it happens outside of a nested scope like a
class or function definition, it's not 'global'. "

Thanks for clearing that up Alex. The reason I liked Jan's solution at
first glance was that it allowed me to manipulate the objects directly
after I created the class. But I am using Shawn's advice now because
it lets me abstract, but still allows me to directly manipulate the
object if I need to.

@ Steven....
"No, you're confused -- the problem isn't with using the global
namespace.
The problem is that you don't know what names you want to use ahead of
time. "

Actually I know what the names would be and how I want to use them.
If you look at my example in the beginning you will notice that it
creates unique objects with unique names, which anyone who looks at
what is being mixed can easily figure out and of course the number and
names of  objects is directly dependent on the mixed elements.
(although perhaps bottle is not the best analogy because the contents
can change, which will not change once the object is created.)
Having a stable and descriptive naming strategy was important,
especially to use the unique object directly, and to not have to go
searching where they might be located at any moment, e.g. if they are
being moved about as part of other data structures. If anyone has any
other thoughts regarding this, I would appreciate them.

- Thanks everyone.



More information about the Python-list mailing list