I have two Python (3.8) scripts located in the same folder.
The first lookup.py is simply:
#! /usr/bin/env python3
import os
from getimp import session0
print (session0)
The second script getimp.py identifies a cookie and sets it as a variable which is imported into the first script. I have omitted some of the code here, but hopefully have the critical parts.
#! /usr/bin/env python3
import os
import json
import base64
import sqlite3
import shutil
from datetime import datetime, timedelta
import win32crypt # pip install pypiwin32
from Crypto.Cipher import AES # pip install pycryptodome
def get_chrome_datetime(chromedate):
    """Return a `datetime.datetime` object from a chrome format datetime
....
....
    # you can also search by domain, e.g thepythoncode.com
    cursor.execute("""
    SELECT host_key, name, value, creation_utc, last_access_utc, expires_utc, encrypted_value
    FROM cookies
    WHERE name like '%user_id%'""")
    # get the AES key
    key = get_encryption_key()
    for host_key, name, value, creation_utc, last_access_utc, expires_utc, encrypted_value in cursor.fetchall():
        if not value:
            decrypted_value = decrypt_data(encrypted_value, key)
        else:
            # already decrypted
            decrypted_value = value
        print(f"""
        {decrypted_value}
        ===============================================================""")
        
    session0 = decrypted_value
if __name__ == "__main__":
    main()
If I run getimp.py on its own it generates the correct result but when I run lookup.py I get an error:
  File "lookup", line 4, in <module>
    from getimp import session0
ImportError: cannot import name 'session0' from 'getimp' (D:\Documents\ptest\getimp.py)
Am I losing the variable once the script getimp.py finishes?
session0variable ingetimp.py. There's asession0variable inside the functionget_chrome_datetime(), but that variable shouldn't be visible outside that function.get_chrome_datetimefunction, try making it global