why doesn’t exec
capture underscore named variables in it’s execution context?
for the program below i can only see “mergesort” in global/local context but not any of the “_xxx” names.
def mergesort(A):
def _merge(A, left, m, right):
left_A, right_A = A[left:m], A[m:right]
left_len, right_len = len(left_A), len(right_A)
l_i, r_i, k = 0, 0, left
while l_i < left_len and r_i < right_len:
if left_A[l_i] <= right_A[r_i]:
A[k] = left_A[l_i]
l_i += 1
k += 1
else:
A[k] = right_A[r_i]
r_i += 1
k += 1
while l_i < left_len:
A[k] = left_A[l_i]
l_i += 1
k += 1
while r_i < right_len:
A[k] = right_A[r_i]
r_i += 1
k += 1
def _mergesort(A, left, right):
if left < right:
m = (left + right)//2
_mergesort(A, m+1, right)
_mergesort(A, left, m)
_merge(A, left, m+1, right+1)
return(A)
return(_mergesort(A, 0, len(A)))