'local' var in module

Aaron Bingham bingham at cenix-bioscience.com
Thu Oct 7 11:25:12 EDT 2004


Andreas Lobinger wrote:

> Aloha,
>
> i'm i little bit confused by the following behaviour...
>
> lobingera at sibyl: cat flip.py
>
[working code deleted]

If you assign to a variable inside a function, it will define a variable 
local to that function, unless you explicity declare that variable as a 
global, like so:

> def g():

global rstate

> random.seed(rstate)
> s = list()
>
> for i in range(paras['flength']):
> s.append(random.choice(paras['cset']))
>
> rstate = random.getseed()
> return "".join(s) 

Aaron




More information about the Python-list mailing list