On Jan 25, 5:31 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Thu, 24 Jan 2008 23:04:42 -0800, Tim Rau wrote:
> > UnboundLocalError: local variable 'nextID' referenced before assignment
>
> When you assign to a name in Python, the compiler treats it as a local
> variable. S
On Fri, 25 Jan 2008 03:28:05 -0800, Tim Rau wrote:
>> Because you don't assign to allThings, and therefore it is treated as
>> global.
>>
>>
> Hmm so I can't assign to globals in a local environment? How do I
> make it see that I'm assigning to a global?
I thought somebody had already mentio
On Jan 25, 5:31 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Thu, 24 Jan 2008 23:04:42 -0800, Tim Rau wrote:
> > UnboundLocalError: local variable 'nextID' referenced before assignment
>
> When you assign to a name in Python, the compiler treats it as a local
> variable. S
On Thu, 24 Jan 2008 23:04:42 -0800, Tim Rau wrote:
> UnboundLocalError: local variable 'nextID' referenced before assignment
When you assign to a name in Python, the compiler treats it as a local
variable. So when you have a line like this:
nextID += 1 # equivalent to nextID = nextID + 1
you
Tim Rau wrote:
> I'm sorry: I forgot to say what my problem was. Python seems to think
> that nextID is a local, and complains that it can't find it. THis is
> not the full text of the function, just the level that is causing
> errors. the lack of : on the if is a transcription error.
> Traceback
On Jan 24, 7:09 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Thu, 24 Jan 2008 15:37:09 -0800, Tim Rau wrote:
> > What makes python decide whether a particular variable
> > is global or local?
>
> For starters, if the line of code is not inside a class or function, that
> i
On Thu, 24 Jan 2008 15:37:09 -0800, Tim Rau wrote:
> What makes python decide whether a particular variable
> is global or local?
For starters, if the line of code is not inside a class or function, that
is, it's at the top level of a module, it is global.
More interesting is if it is inside a
Tim Rau schrieb:
> What makes python decide whether a particular variable is global or
> local? I've got a list and a integer, both defined at top level, no
> indentation, right next to each other:
>
> allThings = []
> nextID = 0
>
> and yet, in the middle of a function, python sees one and doesn
What makes python decide whether a particular variable is global or
local? I've got a list and a integer, both defined at top level, no
indentation, right next to each other:
allThings = []
nextID = 0
and yet, in the middle of a function, python sees one and doesn't see
the other:
class ship(thi
Wolfgang wrote:
> Hi all,
>
> I've started to write some functions but I have some problems with
> common variables in that functions.
>
> So I have some variables which should be accessible by all my functions
> but not accessible by the rest of my code. How can I do this?
You can use a closure
Wolfgang wrote:
>> First, avoid "from function import *" as it pollutes your namespace. Either
>> import specific symbols or just the module:
>>
>> from function import fun, fun1
>> import function
>
> thanks for the hint! But what is the difference between
> from module import *
>
Thanks! I've learned a lot today!
Wolfgang
--
http://mail.python.org/mailman/listinfo/python-list
Wolfgang> thanks for the hint! But what is the difference between
Wolfgang> from module import *
Wolfgang> and
Wolfgang> import module
Wolfgang> ?
Try it and see. I happen to have a.py laying about:
import atexit
def work():
print "whew! work is hard"
d
Wolfgang schrieb:
>> First, avoid "from function import *" as it pollutes your namespace. Either
>> import specific symbols or just the module:
>>
>> from function import fun, fun1
>> import function
>
> thanks for the hint! But what is the difference between
> from module import *
>
>
> First, avoid "from function import *" as it pollutes your namespace. Either
> import specific symbols or just the module:
>
> from function import fun, fun1
> import function
thanks for the hint! But what is the difference between
from module import *
and
import module
?
>
Wolfgang> So I have some variables which should be accessible by all my
Wolfgang> functions but not accessible by the rest of my code. How can I
Wolfgang> do this?
Wolfgang> ###function.py:
Wolfgang> c1=123.0
Wolfgang> c2=134.0
Wolfgang> def fun(temp):
Wolfgang>
Hi all,
I've started to write some functions but I have some problems with
common variables in that functions.
So I have some variables which should be accessible by all my functions
but not accessible by the rest of my code. How can I do this?
Thanks
Wolfgang
###function.py:
c1=123.0
c2=134
17 matches
Mail list logo