这是我不久前正在使用的代码的一部分。我试图修改代码,直到我决定将其恢复。我不明白为什么我的当前和上一个不再被引用,即使它们位于同一函数内。
部分代码
def getSKU():
global current, previous
location = "C:\\Users\\Onboarding\\Downloads\\SKU Awaiting Approval"
namePattern = re.compile(r'exportData')
for filename in os.listdir(location):
if namePattern.match(filename):
full_path = os.path.join(location, filename)
current = pan.read_excel(full_path)
break
current.to_csv("current", index=False)
prev_pattern = re.compile(r"SKU Awaiting Approval")
for filename in os.listdir(location):
if prev_pattern.match(filename):
full_path = os.path.join(location, filename)
previous = pan.read_excel(full_path)
break
试试这个:
def getSKU():
global current, previous
location = "C:\\Users\\Onboarding\\Downloads\\SKU Awaiting Approval"
namePattern = re.compile(r'exportData')
for filename in os.listdir(location):
if namePattern.match(filename):
full_path = os.path.join(location, filename)
current = pan.read_excel(full_path)
break
current.to_csv("current", index=False)
prev_pattern = re.compile(r"SKU Awaiting Approval")
for filename in os.listdir(location):
if prev_pattern.match(filename):
full_path = os.path.join(location, filename)
previous = pan.read_excel(full_path)
break