All, Requirement : i want to call a variable assigned outside a function scope anytime within the function. I read "global" is a way.
a) Case I looks fine. b) Case II is bombing out. Is this how it works or please correct me if i am wrong. case I: In [17]: a = 10 In [19]: def fun_local(): ....: global a ....: print "the value of a is %d" %(a) ....: a = 5 ....: print "the value of a is %d" %(a) ....: In [20]: fun_local() the value of a is 10 the value of a is 5 CASE II: In [21]: a = 10 In [22]: def fun_local(): ....: a = 5 ....: print "the value of a is %d" %(a) ....: global a <input>:4: SyntaxWarning: name 'a' is assigned to before global declaration <input>:4: SyntaxWarning: name 'a' is assigned to before global declaration <input>:4: SyntaxWarning: name 'a' is assigned to before global declaration Thanks, santosh
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor