Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-15 Thread Mark Lawrence
On 14/06/2014 20:37, S Tareq wrote: You appear to be having problems with your keyboard. Could you please resend your message, stating precisely what you wanted to say. Thank you. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our languag

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-15 Thread diliup gabadamudalige
Thank you very much Allan! 100% clear. I thank each and every one of you who contributed to all my question on the above subject. A lot of things became very clear. May you all be well. On Sun, Jun 15, 2014 at 3:15 AM, Alan Gauld wrote: > On 14/06/14 13:53, diliup gabadamudalige wrote: > > Sa

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-14 Thread Alan Gauld
On 14/06/14 13:53, diliup gabadamudalige wrote: Say if I have a lot of Lists, strings and variables used to carry data to and from various functions why can't I have a class with all these in it? You can but it should also have the functions that operate on the data too. Thats the point of cl

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-14 Thread S Tareq
On Friday, 13 June 2014, 12:45, Steven D'Aprano wrote: On Fri, Jun 13, 2014 at 12:51:25PM +0530, diliup gabadamudalige wrote: > Hi All! > Hope everyone is well. > > In my code there are many dictionaries and lists which are used in various > functions. Is it better/pythonic/efficient

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-14 Thread Steven D'Aprano
On Sat, Jun 14, 2014 at 06:23:08PM +0530, diliup gabadamudalige wrote: > Say if I have a lot of Lists, strings and variables used to carry data to > and from various functions why can't I have a class with all these in it? Of course you *can*, but you *should not*. Read on... [...] > so I decla

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-14 Thread diliup gabadamudalige
Thank you all for those great clarifications. I learnt a lot from these. My roots in programming are from the early 80s and with a gap of nearly 30 years till I restarted again last year in March with Python. :) So some of the new concepts like classes are a bit alien to me but I am catching on. I

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-13 Thread Cameron Simpson
On 14Jun2014 11:21, Steven D'Aprano wrote: On Fri, Jun 13, 2014 at 09:42:34PM +0530, diliup gabadamudalige wrote: 2. Lists that are read only are better off being tuples? Possibly. It depends. As a general rule, tuples may be used for heterogeneous data, lists should be used for homogeneous

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-13 Thread Steven D'Aprano
Albert-Jan, I've been meaning to ask for a long time... I don't suppose you're hitting "Forward" rather than "Reply" in your posts are you? Because I've never seen replies from anyone else use the same style as your replies. Further comments below. On Fri, Jun 13, 2014 at 10:14:46AM -0700, Alb

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-13 Thread Steven D'Aprano
On Fri, Jun 13, 2014 at 09:42:34PM +0530, diliup gabadamudalige wrote: > Thank you all for these elaborate explanations. > so would it be wrong to assume that, > 1. the list or dict if 'large' and not mutated is better declared once in a > Class and used throughout the program? There is *no* advan

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-13 Thread Alan Gauld
On 13/06/14 19:20, diliup gabadamudalige wrote: I declare the following dict at the beginning of the program. KEY_SIGNATURES = {"C": [], "G": ["F"], "D": ["F", "C"], "A": ["F", "C", "G"], "E": ["F", "C", "G", "D"], "B": ["F", "C", "G", "D", "A"], "F#": now in the functions when ever I need to

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-13 Thread diliup gabadamudalige
Thank you all for these elaborate explanations. so would it be wrong to assume that, 1. the list or dict if 'large' and not mutated is better declared once in a Class and used throughout the program? or 2. Lists that are read only are better off being tuples? or 3.the list or dict if 'large' and no

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-13 Thread diliup gabadamudalige
Thank you all for these elaborate explanations. so would it be wrong to assume that, 1. the list or dict if 'large' and not mutated is better declared once in a Class and used throughout the program? or 2. Lists that are read only are better off being tuples? or 3.the list or dict if 'large' and no

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-13 Thread Albert-Jan Roskam
- Original Message - > From: Steven D'Aprano > To: tutor@python.org > Cc: > Sent: Friday, June 13, 2014 3:08 PM > Subject: Re: [Tutor] global variables/constants versus volatile > variables/constants > > On Fri, Jun 13, 2014 at 05:10:28AM -

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-13 Thread Steven D'Aprano
On Fri, Jun 13, 2014 at 05:10:28AM -0700, Albert-Jan Roskam wrote: > The other day I used collections.namedtuple and I re-initialized > Record (see below) with every function*) call. Bad idea! It looks > nicer because I did not need a global (and globals are baaad, mkay?), > but it was *much* s

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-13 Thread Albert-Jan Roskam
- Original Message - > From: Steven D'Aprano > To: tutor@python.org > Cc: > Sent: Friday, June 13, 2014 1:45 PM > Subject: Re: [Tutor] global variables/constants versus volatile > variables/constants > > On Fri, Jun 13, 2014 at 12:51:25PM +0530

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-13 Thread Steven D'Aprano
On Fri, Jun 13, 2014 at 12:51:25PM +0530, diliup gabadamudalige wrote: > Hi All! > Hope everyone is well. > > In my code there are many dictionaries and lists which are used in various > functions. Is it better/pythonic/efficient to have these inside the > function itself or declared at the beginn

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-13 Thread Dave Angel
diliup gabadamudalige Wrote in message: > there are many dictionaries and lists which are used in various functions. Is it better/pythonic/efficient to have these inside the function itself or declared at the beginning of the program in which case they will be global? They are all read only. I

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-13 Thread ALAN GAULD
: Friday, 13 June 2014, 9:32 >Subject: Re: [Tutor] global variables/constants versus volatile >variables/constants > > > >thanks Alan! > >in the program that i am writing i used a class called variables and declare >all variables i use in the program in the def __

Re: [Tutor] global variables/constants versus volatile variables/constants

2014-06-13 Thread Alan Gauld
On 13/06/14 08:21, diliup gabadamudalige wrote: In my code there are many dictionaries and lists which are used in various functions. Is it better/pythonic/efficient to have these inside the function itself or declared at the beginning of the program in which case they will be global? If you a

[Tutor] global variables/constants versus volatile variables/constants

2014-06-13 Thread diliup gabadamudalige
Hi All! Hope everyone is well. In my code there are many dictionaries and lists which are used in various functions. Is it better/pythonic/efficient to have these inside the function itself or declared at the beginning of the program in which case they will be global? They are all read only. I und