Skip to content

Commit f548289

Browse files
committed
Demonstration of the wrong way to use globals in lambda functions
1 parent 37ac21e commit f548289

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#! /usr/bin/env python
2+
#
3+
# Do not make this common error
4+
5+
def wrong(w):
6+
return lambda x: x+n
7+
8+
print wrong(2.3)
9+
e = wrong(11.2)
10+
11+
try:
12+
q = e(0.75)
13+
except NameError,m:
14+
print "Well, I guess there was a name error \n%s" % m
15+
16+
n = 14
17+
q2 = e(0.85)
18+
print q2
19+

0 commit comments

Comments
 (0)