[issue24592] global var defined in module not returned by function

2015-07-08 Thread Steve Dower
Steve Dower added the comment: You should start by posting this to python-list or StackOverflow, and I'd suggest including code that can actually be run - it's far more precise than pseudocode. (Functions and modules get used a lot. It's far more likely there's a bug in your code than in

[issue24592] global var defined in module not returned by function

2015-07-08 Thread arthur
New submission from arthur: defined global var, glob.myVar, in separated module imported module containing glob.myVar in function1, func1(): glob.myVar = func1Var = func2() in function2, func2(): if (...): glob.myVar+= abc func2() # call func2() again - recursive else: return glob.myVar I

Re: shortcut for large amount of global var declarations?

2010-05-10 Thread Lawrence D'Oliveiro
In message mailman.2771.1273327690.23598.python-l...@python.org, Alex Hall wrote: ... I have about fifteen vars in a function which have to be global. Why not make them class variables, e.g. class my_namespace : var1 = ... var2 = ... #end my_namespace def

shortcut for large amount of global var declarations?

2010-05-08 Thread Alex Hall
Hi all, I am sorry if this is the second message about this you get; I typed this and hit send (on gmail website) but I got a 404 error, so I am not sure if the previous message made it out or not. Anyway, I have about fifteen vars in a function which have to be global. Is there a faster and more

Re: shortcut for large amount of global var declarations?

2010-05-08 Thread MRAB
Alex Hall wrote: Hi all, I am sorry if this is the second message about this you get; I typed this and hit send (on gmail website) but I got a 404 error, so I am not sure if the previous message made it out or not. Anyway, I have about fifteen vars in a function which have to be global. Is there

Re: shortcut for large amount of global var declarations?

2010-05-08 Thread Jon Clements
On 8 May, 15:08, Alex Hall mehg...@gmail.com wrote: Hi all, I am sorry if this is the second message about this you get; I typed this and hit send (on gmail website) but I got a 404 error, so I am not sure if the previous message made it out or not. Anyway, I have about fifteen vars in a

Re: shortcut for large amount of global var declarations?

2010-05-08 Thread Alex Hall
On 5/8/10, Jon Clements jon...@googlemail.com wrote: On 8 May, 15:08, Alex Hall mehg...@gmail.com wrote: Hi all, I am sorry if this is the second message about this you get; I typed this and hit send (on gmail website) but I got a 404 error, so I am not sure if the previous message made it

Re: shortcut for large amount of global var declarations?

2010-05-08 Thread James Mills
On Sun, May 9, 2010 at 12:08 AM, Alex Hall mehg...@gmail.com wrote: Hi all, I am sorry if this is the second message about this you get; I typed this and hit send (on gmail website) but I got a 404 error, so I am not sure if the previous message made it out or not. Anyway, I have about

Re: shortcut for large amount of global var declarations?

2010-05-08 Thread Jon Clements
On 8 May, 16:03, Alex Hall mehg...@gmail.com wrote: On 5/8/10, Jon Clements jon...@googlemail.com wrote: On 8 May, 15:08, Alex Hall mehg...@gmail.com wrote: Hi all, I am sorry if this is the second message about this you get; I typed this and hit send (on gmail website) but I got a 404

Re: shortcut for large amount of global var declarations?

2010-05-08 Thread Steven D'Aprano
On Sat, 08 May 2010 10:08:08 -0400, Alex Hall wrote: Hi all, I am sorry if this is the second message about this you get; I typed this and hit send (on gmail website) but I got a 404 error, so I am not sure if the previous message made it out or not. Anyway, I have about fifteen vars in a

Global var access in imported modules?

2008-08-27 Thread RgeeK
I have a main module doStuff.py and another module utility.py. At the start of doStuff.py I call import utility.py Then I also proceed to initiallize some global variables sName = Then I create a class, some methods etc. In one of the methods I assign a value to my variable sName.

Re: Global var access in imported modules?

2008-08-27 Thread Fredrik Lundh
RgeeK wrote: I have a main module doStuff.py and another module utility.py. At the start of doStuff.py I call import utility.py that tries to import a module named py from the package utility. Then I also proceed to initiallize some global variables sName = Within my utility.py

Re: Global var access in imported modules?

2008-08-27 Thread Rgg
Fredrik Lundh wrote: import utility.py that tries to import a module named py from the package utility. oops - that was just a typo in my post - I meant of course import utility Python doesn't have program-wide global variables; if you need that, create a support module and import that

Re: Global var access in imported modules?

2008-08-27 Thread RgeeK
Fredrik Lundh wrote: import utility.py that tries to import a module named py from the package utility. oops - that was just a typo in my post - I meant of course import utility Python doesn't have program-wide global variables; if you need that, create a support module and import that

Re: Global var access in imported modules?

2008-08-27 Thread RgeeK
Dennis Lee Bieber wrote: On Wed, 27 Aug 2008 16:21:03 -0400, RgeeK [EMAIL PROTECTED] declaimed the following in comp.lang.python: I have a main module doStuff.py and another module utility.py. At the start of doStuff.py I call import utility.py I hope not... import utility

Re: problem with global var

2008-01-04 Thread Peter Otten
Bruno Ferreira wrote: I wrote a very simple python program to generate a sorted list of lines from a squid access log file. Now that your immediate problem is solved it's time to look at the heapq module. It solves the problem of finding the N largest items in a list much more efficiently. I

Re: problem with global var

2008-01-04 Thread Bruno Ferreira
Hello all, Amazing :) The program is working properly now, the code is much better and I learned a bit more Python. Thank you all, guys. Bruno. 2008/1/4, Peter Otten [EMAIL PROTECTED]: Bruno Ferreira wrote: I wrote a very simple python program to generate a sorted list of lines from a

problem with global var

2008-01-03 Thread Bruno Ferreira
Hi, I wrote a very simple python program to generate a sorted list of lines from a squid access log file. Here is a simplified version: ## 1 logfile = open (squid_access.log, r) 2 topsquid = [[0, 0, 0, 0, 0, 0, 0]] 3 4 def add_sorted (list): 5 for i in

Re: problem with global var

2008-01-03 Thread Matt Nordhoff
Bruno Ferreira wrote: Hi, I wrote a very simple python program to generate a sorted list of lines from a squid access log file. Here is a simplified version: ## 1 logfile = open (squid_access.log, r) 2 topsquid = [[0, 0, 0, 0, 0, 0, 0]] 3 4 def

Re: problem with global var

2008-01-03 Thread wes
Bruno Ferreira wrote: Hi, I wrote a very simple python program to generate a sorted list of lines from a squid access log file. Here is a simplified version: ## 1 logfile = open (squid_access.log, r) 2 topsquid = [[0, 0, 0, 0, 0, 0, 0]] 3 4 def

Re: problem with global var

2008-01-03 Thread Diez B. Roggisch
Bruno Ferreira wrote: Hi, I wrote a very simple python program to generate a sorted list of lines from a squid access log file. Here is a simplified version: ## 1 logfile = open (squid_access.log, r) 2 topsquid = [[0, 0, 0, 0, 0, 0, 0]] 3 4 def

Re: problem with global var

2008-01-03 Thread Fredrik Lundh
Bruno Ferreira wrote: When I execute the program _without_ the lines 10 and 11: 10 if len(topsquid) 50: 11 topsquid = topsquid[0:50] it runs perfectly. But if I execute the program _with_ those lines, this exception is thrown: [EMAIL PROTECTED]:~$ python topsquid.py

Re: problem with global var

2008-01-03 Thread Steven D'Aprano
On Thu, 03 Jan 2008 11:38:48 -0300, Bruno Ferreira wrote: Hi, I wrote a very simple python program to generate a sorted list of lines from a squid access log file. Here is a simplified version: ## 1 logfile = open (squid_access.log, r) 2 topsquid =

Re: Count nb call of a function, without global var or decorator

2007-02-06 Thread Duncan Booth
Méta-MCI [EMAIL PROTECTED] wrote: Example, with meta-data (attributs of function) : def ff(this): try: this.count=this.count+1 except: this.count=1 a=1 b=2 c=a+b ff(ff) fa=ff ff(ff) fa(fa) print ff.count How to improve that? If I've

Re: Count nb call of a function, without global var or decorator

2007-02-05 Thread M�ta-MCI
Re! I can do : def ff(): this=ff try: this.count=this.count+1 except: this.count=1 a=1 b=2 c=a+b ff() fa=ff ff() fa() print ff.count But that use, inside the function, the litteral name of the function; and I want no use litteral name (inside) @+

Re: Count nb call of a function, without global var or decorator

2007-02-05 Thread Bjoern Schliessmann
Méta-MCI wrote: Example, with meta-data (attributs of function) : Apart from asking what counting nb call of a function means, I wonder why you didn't use an iterator? @-salutations @-less Regards, Björn -- BOFH excuse #65: system needs to be rebooted --

Re: Count nb call of a function, without global var or decorator

2007-02-05 Thread M�ta-MCI
Re! why you didn't use an iterator? If the iterator is extern (to the function), it's like decorator, or global var. If it is internal, it's huge, compare to this.count=this.count+1 (or this.count+=1) @+ Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list

Re: Count nb call of a function, without global var or decorator

2007-02-05 Thread Bjoern Schliessmann
Méta-MCI wrote: If the iterator is extern (to the function), it's like decorator, or global var. Please excuse me, I don't understand your point. I'm not even sure if both of us speak of the same iterators. If it is internal, it's huge, compare to this.count=this.count+1 (or this.count+=1

Re: global var

2005-02-21 Thread Jeff Shannon
Nick Coghlan wrote: Michael Hoffman wrote: raver2046 wrote: How to have a global var in python ? global var will give you a global variable named var. Whether this advice is correct or not depends greatly on what the OP means by 'global' :) Module global, it's right, application global it's

Re: global var

2005-02-19 Thread Nick Coghlan
Michael Hoffman wrote: raver2046 wrote: How to have a global var in python ? global var will give you a global variable named var. Whether this advice is correct or not depends greatly on what the OP means by 'global' :) Module global, it's right, application global it's wrong. Given the nature

global var

2005-02-17 Thread raver2046
hello, How to have a global var in python ? thank you. raver2046 http://raver2046.ath.cx -- http://mail.python.org/mailman/listinfo/python-list

Re: global var

2005-02-17 Thread Michael Hoffman
raver2046 wrote: How to have a global var in python ? global var will give you a global variable named var. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list

Re: global var

2005-02-17 Thread Steven Bethard
raver2046 wrote: How to have a global var in python ? You can, but you probably don't want to. What's your use case? Example code and what you'd like it to do would be helpful. STeVe -- http://mail.python.org/mailman/listinfo/python-list