Re: [Tutor] dict vs several variables?

2012-02-18 Thread Peter Otten
Leam Hall wrote: On 02/17/2012 09:26 AM, Dave Angel wrote: There are two ways to think of a class. One is to hold various related data, and the other is to do operations on that data. If you just consider the first, then you could use a class like a dictionary whose keys are fixed (known at

Re: [Tutor] dict vs several variables?

2012-02-18 Thread Leam Hall
On 02/18/2012 03:39 AM, Peter Otten wrote: Leam Hall wrote: On 02/17/2012 09:26 AM, Dave Angel wrote: There are two ways to think of a class. One is to hold various related data, and the other is to do operations on that data. If you just consider the first, then you could use a class like a

Re: [Tutor] dict vs several variables?

2012-02-17 Thread Peter Otten
Leam Hall wrote: I'm building a program that uses one of my own modules for a bunch of formula defs and another module for the tkinter GUI stuff. There are half a dozen input variables and about the same in calculated variables. Is it better/cleaner to just build a global dict and have

Re: [Tutor] dict vs several variables?

2012-02-17 Thread leam hall
Thanks Peter! My concern with variables is that they have to be passed in specific order to the function, and they may have to have their type set multiple times so that you can perform the right functions on them. In a dict you could set it on insert and not have to worry about it. Thanks!

Re: [Tutor] dict vs several variables?

2012-02-17 Thread Sander Sweers
On 17 February 2012 14:04, leam hall leamh...@gmail.com wrote: My concern with variables is that they have to be passed in specific order to the function, and they may have to have their type set multiple times so that you can perform the right functions on them. In a dict you could set it on

Re: [Tutor] dict vs several variables?

2012-02-17 Thread Dave Angel
On 2/17/12, Peter Otten__pete...@web.de wrote: Leam Hall wrote: I'm building a program that uses one of my own modules for a bunch of formula defs and another module for the tkinter GUI stuff. There are half a dozen input variables and about the same in calculated variables. Is it

Re: [Tutor] dict vs several variables?

2012-02-17 Thread Peter Otten
leam hall wrote: My concern with variables is that they have to be passed in specific order to the function, Yes, unless you use keywords. You can invoke def div(x, y): return x // y a = div(3, 2) b = div(y=3, x=2) assert a == b and they may have to have their type set I have no idea

Re: [Tutor] dict vs several variables?

2012-02-17 Thread leam hall
On 2/17/12, Dave Angel d...@davea.name wrote: Real question is whether some (seldom all) of those variables are in fact part of a larger concept. If so, it makes sense to define a class for them, and pass around objects of that class. Notice it's not global, it's still passed as an

Re: [Tutor] dict vs several variables?

2012-02-17 Thread leam hall
On 2/17/12, Peter Otten __pete...@web.de wrote: leam hall wrote: and they may have to have their type set I have no idea what you mean by have their type set. Can you give an example? Peter, The variables input seem to be assumed to be strings and I need them to be an integer or a float

Re: [Tutor] dict vs several variables?

2012-02-17 Thread Dave Angel
On 02/17/2012 09:06 AM, leam hall wrote: On 2/17/12, Dave Angeld...@davea.name wrote: Real question is whether some (seldom all) of those variables are in fact part of a larger concept. If so, it makes sense to define a class for them, and pass around objects of that class. Notice it's not

Re: [Tutor] dict vs several variables?

2012-02-17 Thread Peter Otten
leam hall wrote: On 2/17/12, Peter Otten __pete...@web.de wrote: leam hall wrote: and they may have to have their type set I have no idea what you mean by have their type set. Can you give an example? Peter, The variables input seem to be assumed to be strings and I need them to be

Re: [Tutor] dict vs several variables?

2012-02-17 Thread Alan Gauld
On 17/02/12 14:10, leam hall wrote: The variables input seem to be assumed to be strings They are not assumed to be strings, they *are* strings. Users can only type characters at the keyboard (the usual source of input). Your program has to interpret those characters and convert to the

Re: [Tutor] dict vs several variables?

2012-02-17 Thread Leam Hall
On 02/17/2012 09:26 AM, Dave Angel wrote: There are two ways to think of a class. One is to hold various related data, and the other is to do operations on that data. If you just consider the first, then you could use a class like a dictionary whose keys are fixed (known at compile time). I

Re: [Tutor] dict vs several variables?

2012-02-17 Thread Steven D'Aprano
Leam Hall wrote: I'm building a program that uses one of my own modules for a bunch of formula defs and another module for the tkinter GUI stuff. There are half a dozen input variables and about the same in calculated variables. Is it better/cleaner to just build a global dict and have