I don't understand why I cannot set a global variable driver in Selenium
I get this error in the Load() function on driver
Exception has occurred: AttributeError
'NoneType' object has no attribute 'get'
  File "D:\Code\edge_script.py", line xx, in load
    driver.get("https://www.google.com")
    ^^^^^^^^^^
  File "D:\Code\edge_script.py", line xx, in main
    load()
  File "D:\Code\edge_script.py", line xx, in <module>
    main()
AttributeError: 'NoneType' object has no attribute 'get'
code is below
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from pathlib import Path
import time
import subprocess
import re
from msedge.selenium_tools import Edge, EdgeOptions
#global variables
driver = None
    
def init():
    subprocess.run("taskkill /f /im msedge.exe")
    edge_options = EdgeOptions()
    edge_options.use_chromium = True    
    #Here you set the path of the profile ending with User Data not the profile folder
    path  = "user-data-dir="+str(Path.home())+"\\AppData\\Local\\Microsoft\\Edge\\User Data"
    print(path)
    edge_options.add_argument(path); 
    #Here you specify the actual profile folder    
    edge_options.add_argument("--profile-directory=Default")
    edge_options.add_argument("--no-sandbox") 
    edge_options.add_argument("--disable-setuid-sandbox") 
    edge_options.add_argument("--remote-debugging-port=9222") 
    edge_options.add_argument("--disable-dev-shm-using") 
    edge_options.add_argument("--disable-extensions") 
    edge_options.add_argument("--disable-gpu") 
    edge_options.binary_location = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"
    driver = Edge(options = edge_options, executable_path = "D:\\msedgedriver.exe")
def load():
    # navigate to the website
    driver.get("https://www.google.com") #<<<ERROR HERE
    # wait for the page to load
    time.sleep(5)
def close():
    # close the driver
    driver.quit()
def main():
    init()
    load()
    close()
if __name__ == "__main__":
    main()
 
    