[BangPypers] Simple syntactic error?
Pradeep Gowda
pradeep at btbytes.com
Thu May 22 21:25:26 CEST 2008
On 22-May-08, at 3:14 PM, g sobers wrote:
> hey!
>
> Following is a small PyS60 script. The error seems related to basic
> syntax - "state" in keys() is not recognized although defined
> globally.
>
> Would appreciate assistance.
>
> =============================================
> import appuifw, key_codes, e32, telephone
> state = None
>
> def keys(event):
> if event['keycode'] == key_codes.EKeyYes:
> appuifw.note(u"Doesn't Matter")
> elif (event['keycode'] == key_codes.EKeyYes) and (state ==
> telephone.EStatusConnected):
> appuifw.note(u"Yes was pressed and call active")
>
> def cb_calling(args):
> state = args[0]
>
> def quit():
> app_lock.signal()
>
> telephone.call_state(cb_calling)
> canvas = appuifw.Canvas(event_callback = keys)
> appuifw.app.body = canvas
> appuifw.app.exit_key_handler = quit
> app_lock = e32.Ao_lock()
> app_lock.wait()
> ==============================================
>
> Best,
> wirefree
>
See the code below
>>> state = 99
>>> def foo(vars):
... state = vars[0]
...
>>> foo([1,2])
>>> state
99
#------ this is what is happening to your code
# so... try this...
>>> def foo(vars):
... global state
... state = vars[0]
...
>>> foo([1,2])
>>> state
1
>>>
You have declare state as "global" inside the function.
By default the scope of the variable is local.
More information about the BangPypers
mailing list