I am trying to insert data from a .txt file to a SQLite database but whenever I run my code I get this error: NameError: name 'get_value' is not defined
. Is this because im trying to call a function in a function inside of a class? I didn't include the other parts of my code because I didn't think they are needed but if they are let me know and I'll add it.
Python File:
class InputFromIPLog:
...
def get_value():
info = item.strip().split(':')
val = info[1].strip().split(',')
return val[0].strip()
def insert_data():
with open(f"new_iplog.txt", "r") as f:
file_data = f.readlines()
input_gamertag = ""
input_ip_address = ""
input_xuid = ""
input_mid = ""
for item in file_data:
if "Gamertag" in item:
input_gamertag = get_value(item)
elif "IP Address" in item:
input_ip_address = get_value(item)
elif 'XUID' in item:
input_xuid = get_value(item)
elif 'MID' in item:
input_mid = get_value(item)
cursor.execute("INSERT INTO userinfo (gamertag, ip, xuid, mid) values(?, ?, ?)", (input_gamertag, input_ip_address, input_xuid, input_mid,))
...
new_iplog.txt File:
...
Gamertag: UnknownUser
IP Address: 10.0.0.1
XUID: 000301F23B9F6ED4
MID: FB00FDA037CEB46E
Gamertag: AnotherUnknownUser
IP Address: 1.1.1.1
XUID: 0009000005E96E9B
MID: FB00F5413910FEDD
...