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 versusvolatile > 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

Re: [Tutor] global variables

2013-08-22 Thread wolfrage8...@gmail.com
Steve, Thanks for all of this information. It seems the OP has sparked the kind of discussion that I had hopped for when I posted http://thread.gmane.org/gmane.comp.python.tutor/83251 Luckily though I did get an excellent response from Alan. http://thread.gmane.org/gmane.comp.python.tutor/83251/

Re: [Tutor] global variables

2013-08-22 Thread Matthew Ngaha
On Thu, Aug 22, 2013 at 4:35 PM, Steven D'Aprano wrote: > Good question! And one that needs a long answer. Hey i just checked mail again... A big thank you for your responses, i will read all of them now.. im pretty my programs/designs will be much cleaner by the time i done. And yes i was talki

Re: [Tutor] global variables

2013-08-22 Thread Steven D'Aprano
On 23/08/13 00:59, Andy McKenzie wrote: Isn't object orientation kind of the whole POINT of Python? From python.org: "Python is an interpreted, object-oriented, high-level programming language with dynamic semantics." Well, yes and no. Python is an object-oriented language in the sense that

Re: [Tutor] global variables

2013-08-22 Thread Steven D'Aprano
On 23/08/13 00:12, Matthew Ngaha wrote: On Thu, Aug 22, 2013 at 2:52 PM, Chris Down wrote: I would doubt that anyone has told you "don't ever use classes", because that's nonsense; you've probably misread a dissuasion from that path in a single instance as applying more broadly than was intende

Re: [Tutor] global variables

2013-08-22 Thread Steven D'Aprano
On 22/08/13 23:52, Chris Down wrote: On 2013-08-22 14:43, Matthew Ngaha wrote: I don't feel my program needs a class. Also i have been told to stop using classes by some very experienced Python programmers on irc even though i don't see why. It's confusing being told different things. Well, if

Re: [Tutor] global variables

2013-08-22 Thread Steven D'Aprano
On 22/08/13 22:36, Matthew Ngaha wrote: My question is how many global variables did your last decent sized program have? Also please share any insight you have about them. I do try to avoid them, but is this always possible? Eiffel is another language that aims to eliminate global variables e

Re: [Tutor] global variables

2013-08-22 Thread Steven D'Aprano
On 22/08/13 22:36, Matthew Ngaha wrote: I'm always told to avoid using them. I read discussions on the python irc channel about them but honestly i feel there are some times where i can't avoid using them. Like where i want to keep track of a state variable in many different functions that may or

Re: [Tutor] global variables

2013-08-22 Thread Steven D'Aprano
On 22/08/13 23:43, Matthew Ngaha wrote: On Thu, Aug 22, 2013 at 1:40 PM, Chris Down wrote: It sounds like you want to use a class. Why would you not just use a class if you want to store state? I don't feel my program needs a class. Also i have been told to stop using classes by some very ex

Re: [Tutor] global variables

2013-08-22 Thread Andy McKenzie
On Thu, Aug 22, 2013 at 10:12 AM, Matthew Ngaha wrote: > On Thu, Aug 22, 2013 at 2:52 PM, Chris Down wrote: > >I would doubt that anyone has told you "don't ever use classes", because > > that's nonsense; you've probably misread a dissuasion from that path in a > > single instance as applying mo

Re: [Tutor] global variables

2013-08-22 Thread Joel Goldstick
On Thu, Aug 22, 2013 at 10:12 AM, Matthew Ngaha wrote: > On Thu, Aug 22, 2013 at 2:52 PM, Chris Down wrote: >>I would doubt that anyone has told you "don't ever use classes", because >> that's nonsense; you've probably misread a dissuasion from that path in a >> single instance as applying more b

Re: [Tutor] global variables

2013-08-22 Thread Chris Down
On 2013-08-22 15:12, Matthew Ngaha wrote: > I am being totally honest here. I was very confused at the time and i said i > didn't agree because it's what i had put so much effort into learning. They > went on to say at some well known Python talks speakers have stated why using > OOP (especially in

Re: [Tutor] global variables

2013-08-22 Thread Matthew Ngaha
On Thu, Aug 22, 2013 at 3:04 PM, Alan Gauld wrote: > On 22/08/13 13:36, Matthew Ngaha wrote: > Global variables in themselves are not the problem. > It's how they tend to get used that causes problems. > Globals that are only changed via a set of > dedicated functions are not topo much of a > p

Re: [Tutor] global variables

2013-08-22 Thread Matthew Ngaha
On Thu, Aug 22, 2013 at 2:52 PM, Chris Down wrote: >I would doubt that anyone has told you "don't ever use classes", because > that's nonsense; you've probably misread a dissuasion from that path in a > single instance as applying more broadly than was intended. I am being totally honest here. I

Re: [Tutor] global variables

2013-08-22 Thread Alan Gauld
On 22/08/13 14:43, Matthew Ngaha wrote: On Thu, Aug 22, 2013 at 1:40 PM, Chris Down wrote: It sounds like you want to use a class. Why would you not just use a class if you want to store state? Local coding conventions or programmer skill levels may preclude it. I don't feel my program need

Re: [Tutor] global variables

2013-08-22 Thread Alan Gauld
On 22/08/13 13:36, Matthew Ngaha wrote: I'm always told to avoid using them. Global variables in themselves are not the problem. It's how they tend to get used that causes problems. Read-only global values - aka constants (so not really variables!) - are not an issue. Globals that are only ch

Re: [Tutor] global variables

2013-08-22 Thread Chris Down
On 2013-08-22 14:43, Matthew Ngaha wrote: > I don't feel my program needs a class. Also i have been told to stop > using classes by some very experienced Python programmers on irc even > though i don't see why. It's confusing being told different things. Well, if you want to store state, you shoul

Re: [Tutor] global variables

2013-08-22 Thread Matthew Ngaha
On Thu, Aug 22, 2013 at 1:40 PM, Chris Down wrote: > It sounds like you want to use a class. > Why would you not just use a class if you want to store state? I don't feel my program needs a class. Also i have been told to stop using classes by some very experienced Python programmers on irc even

Re: [Tutor] global variables

2013-08-22 Thread Chris Down
On 2013-08-22 13:36, Matthew Ngaha wrote: > I'm always told to avoid using them. I read discussions on the python > irc channel about them but honestly i feel there are some times where > i can't avoid using them. Like where i want to keep track of a state > variable in many different functions tha

[Tutor] global variables

2013-08-22 Thread Matthew Ngaha
I'm always told to avoid using them. I read discussions on the python irc channel about them but honestly i feel there are some times where i can't avoid using them. Like where i want to keep track of a state variable in many different functions that may or may not alter its value and also not want

Re: [Tutor] Global Variables

2013-06-22 Thread Steven D'Aprano
On 22/06/13 18:09, Jack Little wrote: Is there a way to keep a global throughout multiple def statements? Oh, a further thought! Perhaps you mean something like this? x = 42 # Global value. def function_one(): global x # Define it once. code using global x goes here... def functio

Re: [Tutor] Global Variables

2013-06-22 Thread Steven D'Aprano
On 22/06/13 18:09, Jack Little wrote: Is there a way to keep a global throughout multiple def statements? I don't understand the question. The only way to *not* keep a global through multiple def statements is if you delete the global: x = 1 # Global. def function_one(): code goes here

[Tutor] Global Variables

2013-06-22 Thread Jack Little
Is there a way to keep a global throughout multiple def statements? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Global Variables

2009-11-21 Thread ALAN GAULD
> > This looks for or creates an nl in your module. > Beg to differ- global will not create it. > > def f():global a > What it does is alert the compiler that assignment to the > variable will make it global. Thats what I meant, that an assignment to a variable marked as global inside a fun

Re: [Tutor] Global Variables

2009-11-21 Thread bob gailer
Alan Gauld wrote: dname() def dname(): global nl This looks for or creates an nl in your module. Beg to differ- global will not create it. def f():global a ... >>> a Traceback (most recent call last): File "", line 1, in NameError: name 'a' is not defined What it does is ale

Re: [Tutor] Global Variables

2009-11-20 Thread Luke Paireepinart
On Fri, Nov 20, 2009 at 4:44 PM, Joseph Fennell wrote: > My apologies yes these are in seperate files, > -- > main.py > --- > cHandler.execute("SELECT * FROM table") > > #sets results from above to nl > > nl = cHandler.fetchall() > > dn = raw_input("User input: ") > > nl2

Re: [Tutor] Global Variables

2009-11-20 Thread Alan Gauld
"Joseph Fennell" wrote I assume that it's because the variable is considered local and the imported functions are not technically local to that document. global in Python means "in the same module" not global across all modules You are best to pass data into functions as arguments and to pa

Re: [Tutor] Global Variables

2009-11-20 Thread Luke Paireepinart
On Fri, Nov 20, 2009 at 2:51 PM, Joseph Fennell wrote: > Quick introduction, I'm Joseph Fennell, and I've been playing with python > for the past 6 years (primarily in the interpreter) and have finally gotten > started on a full project and I've run into a small problem. I have defined > some m

[Tutor] Global Variables

2009-11-20 Thread Joseph Fennell
Quick introduction, I'm Joseph Fennell, and I've been playing with python for the past 6 years (primarily in the interpreter) and have finally gotten started on a full project and I've run into a small problem. I have defined some modules, and when I import them into the page I want to use them o

Re: [Tutor] Global variables

2006-08-16 Thread Kermit Rose
From: Alan Gauld Date: 08/15/06 03:37:21 To: Kermit Rose; [EMAIL PROTECTED] Cc: tutor@python.org; [EMAIL PROTECTED] Subject: Re: [Tutor] Global variables . The names have very little to do with it, the danger of global variable use is the reliance on side-effects and the tight

Re: [Tutor] Global variables

2006-08-16 Thread Kermit Rose
From: Bob Gailer Date: 08/14/06 20:24:00 To: [EMAIL PROTECTED]; tutor@python.org Subject: RE: [Tutor] Global variables A while back you attached factor34.py. Is that the program you are having trouble with? Yes! And you said it misbehaves "consistently with certain nu

Re: [Tutor] Global variables

2006-08-15 Thread Alan Gauld
> That may be true but you will make your code much less reusable > and much more error propne in the process. There are good reasons > why global variables are considered evil... > > But in fact I use the same variable names in the subroutine > parameter list > as in the calling routine for ever

Re: [Tutor] Global variables

2006-08-14 Thread Bob Gailer
A while back you attached factor34.py. Is that the program you are having trouble with? And you said it misbehaves "consistently with certain numbers to be factored." What are these numbers? -- Bob Gailer 510-978-4454 ___ Tutor maillist - Tutor@pyt

Re: [Tutor] Global variables

2006-08-14 Thread Luke Paireepinart
Kermit Rose wrote: > > > From: Alan Gauld > Date: 08/14/06 18:42:41 > To: Kermit Rose; Luke Paireepinart > Cc: tutor@python.org; Danny Yoo > Subject: Re: [Tutor] Global variables > > > That may be true but you will make your code much less reusable >

Re: [Tutor] Global variables

2006-08-14 Thread John Fouhy
On 15/08/06, Kermit Rose <[EMAIL PROTECTED]> wrote: > My routine strongfac calculates a value for fac in the subroutine, and the > calling routine picks up a different vaalue. > > An illustration. > > In strong fac: > > fac = [1,2,3] > print fac > return fac > > in fermat: > > fac = strongfac(z) >

Re: [Tutor] Global variables

2006-08-14 Thread Kermit Rose
From: Alan Gauld Date: 08/14/06 18:42:41 To: Kermit Rose; Luke Paireepinart Cc: tutor@python.org; Danny Yoo Subject: Re: [Tutor] Global variables That may be true but you will make your code much less reusable and much more error propne in the process. There are good reasons why

Re: [Tutor] Global variables

2006-08-14 Thread Kermit Rose
From: Luke Paireepinart Date: 08/14/06 17:17:13 To: Kermit Rose Cc: Danny Yoo; tutor@python.org Subject: Re: [Tutor] Global variables > From: Luke Paireepinart > > are you asking a question? > > > Kermit Rose wrote: > > > Yes. How can I make a package

Re: [Tutor] Global variables

2006-08-14 Thread Alan Gauld
>> If I can figure out how to make my main function subroutine declare >> global >> variables then I won't need to pass parameters most parameters to >> the other >> subroutines, That may be true but you will make your code much less reusable and much more error propne in the process. There are

Re: [Tutor] Global variables

2006-08-14 Thread Luke Paireepinart
> From: Luke Paireepinart > > are you asking a question? > > > Kermit Rose wrote: > > > Yes. How can I make a package of functions declare global variables for > passing information between > the functions in the package? > > a 'package' meaning a module? If you think you need g

Re: [Tutor] Global variables

2006-08-14 Thread Kermit Rose
From: Luke Paireepinart Date: 08/13/06 22:28:50 To: Kermit Rose Cc: Danny Yoo; tutor@python.org Subject: Re: [Tutor] Global variables Kermit Rose wrote: > > > From: Danny Yoo > Date: 08/09/06 16:23:35 > To: Kermit Rose > Cc: tutor@python.org > > >

Re: [Tutor] Global variables

2006-08-13 Thread Luke Paireepinart
Kermit Rose wrote: > > > From: Danny Yoo > Date: 08/09/06 16:23:35 > To: Kermit Rose > Cc: tutor@python.org > > > If I can figure out how to make my main function subroutine declare global > variables > then I won't need to pass parameters most parameters to the other > subroutines, >

[Tutor] Global variables

2006-08-13 Thread Kermit Rose
From: Danny Yoo Date: 08/09/06 16:23:35 To: Kermit Rose Cc: tutor@python.org If I can figure out how to make my main function subroutine declare global variables then I won't need to pass parameters most parameters to the other subroutines, and will bypass the problem I'm having that

[Tutor] Global Variables

2006-08-09 Thread Magnus Wirström
Hi I know that this was in the list in the last days but i deleted it by mistake. How to use global variables? Or perhaps you could point me to another solution. I'm converting a packup app that i made to a gui driven app. The console app was very straight forward and didn't use any own functi