I think I am making a very basic mistake but I can't seem to figure it out. The error is mentioned below but I am confused because wb is defined in open_xl_file():
When I try to call the functions from another script
import openpyxl
import os
import re
def open_xl_file():
loc = input("Please enter path of the file:")
os.chdir(loc)
file = input("Filename:")
wb = openpyxl.load_workbook(file)
def sheet_select():
check = input("Have you called open_xl_file? If yes Press 1 else press 2: ")
print(check)
if int(check) != 1:
open_xl_file()
sheet = input("Which Sheet do you want to email?\n")
wb.get_sheet_by_name(sheet)
sheet
else:
sheet = input("Which State do you want to email?\n")
wb.get_sheet_by_name(sheet)
sheet
Error log:
NameError: name 'wb' is not defined.