RE: Python's equivalent to Main calling program and subprograms

2010-12-01 Thread m b



> >
> > if __name__ == "__main__":
> > main()

What does this mean?

/Mikael
  -- 
http://mail.python.org/mailman/listinfo/python-list


scope of variable

2010-08-20 Thread M B
Hi, 
I try to learn python.
I don't understand this:

(running in idle)

>>> dept=0
>>> def mud():
print dept


>>> mud()
0
>>> def mud():
dept+=1
print dept


>>> mud()
Traceback (most recent call last):
  File "", line 1, in 
mud()
  File "", line 2, in mud
dept+=1
UnboundLocalError: local variable 'dept' referenced before assignment
>>> 

Regards MB

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: scope of variable

2010-08-20 Thread M B
fre 2010-08-20 klockan 13:19 -0600 skrev Burton Samograd:
> M B  writes:
> 
> > Hi, 
> >>>> dept=0
> >>>> def mud():
> > print dept
> >
> > 
> >>>> mud()
> > 0
> >>>> def mud():
> > dept+=1
> > print dept
> 
> You should add a global statement or else python thinks a variable used
> is a local:
> 
> >>> def mud():
> global dept
>   dept+=1
>   print dept
> 
> --
> Burton Samograd
> 
Ok.  Thanks for the answers. :)  I was a bit puzzled of
the fact that I could read but not assign to a global variable.

-- 
http://mail.python.org/mailman/listinfo/python-list