-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path70-scopes.py
More file actions
57 lines (45 loc) · 829 Bytes
/
70-scopes.py
File metadata and controls
57 lines (45 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
Advanced: scopes and namespaces
"""
# import self
import __main__
# scopes
e = 1
def scope1():
e = 2
print('scope1', e)
def scope2():
global e
e = 3
print('scope2', e)
scope2()
print('scope1', e)
print('scope0', e)
scope1()
print('scope0', e)
# Try block execution logic
def funct(store):
store['key_a'] = 'value_a'
store['key_b'] = 'value_b'
e = 1
try:
print("try with return")
store['key_c'] = 'value_c'
e = 2
return e
except Exception:
print('catch exception')
e = 6
else:
print('try else')
e = 5
finally:
print("try finally")
e = 3
del store['key_a']
del store['key_c']
return e
store = {}
ret = funct(store)
print(ret)
print(store)