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

2010-01-04 Thread Nav
I have a class of let's say empty bottle which can have a mix of two items. I want to create let's say 30 of these objects which will have names based on the 2 attributes (apple juice, beer, grape juice, beer, etc) that I provide from a list. All the objects are a mix of (1 of three alcohols) and

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

2010-01-04 Thread Shawn Milochik
You could put them in a dictionary with the key being the name, instead of a list. Shawn -- http://mail.python.org/mailman/listinfo/python-list

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

2010-01-04 Thread Chris Rebert
On Mon, Jan 4, 2010 at 1:32 PM, Shawn Milochik sh...@milochik.com wrote: You could put them in a dictionary with the key being the name, instead of a list. To illustrate that for the OP: name2drink = {} for booze in liquors: for juice in juices: name = juice + +booze # or however

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

2010-01-04 Thread Jan Kaliszewski
2010-01-04, 22:54:41 Chris Rebert c...@rebertia.com wrote: name2drink = {} for booze in liquors: for juice in juices: name = juice + +booze # or however you're naming them drink = Bottle(booze, juice) name2drink[name] = drink @Nav: ...and if you really desire to

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

2010-01-04 Thread Nav
On Jan 4, 4:54 pm, Chris Rebert c...@rebertia.com wrote: On Mon, Jan 4, 2010 at 1:32 PM, Shawn Milochik sh...@milochik.com wrote: You could put them in a dictionary with the key being the name, instead of a list. To illustrate that for the OP: name2drink = {} for booze in liquors:    

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

2010-01-04 Thread Shawn Milochik
On Jan 4, 2010, at 5:59 PM, Nav wrote: On Jan 4, 4:54 pm, Chris Rebert c...@rebertia.com wrote: On Mon, Jan 4, 2010 at 1:32 PM, Shawn Milochik sh...@milochik.com wrote: You could put them in a dictionary with the key being the name, instead of a list. To illustrate that for the OP:

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

2010-01-04 Thread Steve Holden
Nav wrote: On Jan 4, 4:54 pm, Chris Rebert c...@rebertia.com wrote: On Mon, Jan 4, 2010 at 1:32 PM, Shawn Milochik sh...@milochik.com wrote: You could put them in a dictionary with the key being the name, instead of a list. To illustrate that for the OP: name2drink = {} for booze in

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

2010-01-04 Thread Nav
Thanks Jan, You read my mind. That is exactly what I needed. Thanks for showing the product function from itertools as well. It seems easier to grasp than the nested loops, I had been using. I noticed chopin.edu.pl. Are you a musician? Nav -- http://mail.python.org/mailman/listinfo/python-list

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

2010-01-04 Thread alex23
On Jan 5, 9:33 am, Nav navjotmu...@gmail.com wrote: what are the risks of globalnamespace use You're unnecessarily tying your code to the implementation. and what are the benefits? Absolutely none that using a dictionary doesn't also give you. --

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

2010-01-04 Thread Nav
Okay, let me ask another question: When we create instances of objects by doing x = className () are we using globalnamespace? 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? Second why

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

2010-01-04 Thread Nav
Thanks for pointing it out Steve. The blog post doesn't explain it very well. I understand the risk of exec or eval(input). but what are the risks of globalnamespace use and what are the benefits? -- http://mail.python.org/mailman/listinfo/python-list

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

2010-01-04 Thread Steven D'Aprano
On Mon, 04 Jan 2010 19:12:53 -0800, Nav wrote: Okay, let me ask another question: When we create instances of objects by doing x = className() are we using globalnamespace? That depends on whether you are doing x = className() inside a function (or class), or in the top level of the

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

2010-01-04 Thread alex23
On Jan 5, 1:12 pm, Nav navjotmu...@gmail.com wrote: When we create instances of objects by doing x = className () are we using globalnamespace? Well, you're using a namespace, which namespaces its in would depend on the scope in which that assignment occurred. And there's not really a global

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

2010-01-04 Thread Dave Angel
(You top-posted. It's polite on most newsgroups, and specifically on this one to add your comments *following* the quoted earlier text) Nav wrote: Okay, let me ask another question: When we create instances of objects by doing x = className () are we using globalnamespace? If that line

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

2010-01-04 Thread Nav
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

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

2010-01-04 Thread Steven D'Aprano
On Mon, 04 Jan 2010 21:27:12 -0800, Nav wrote: @ 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. You