Hello! I am trying to make my own language and I came across a problem.
I want it to check the type of data the user inputted, but the thing is that its a string.
And as I was looking for sources, I thought of eval() but they said they could hack into my computer.
I also resided to isinstance, but it will always result in True ONLY if I'm checking if its a string.
So how can I get the type of a variable in a string type while not using eval()?
Full Code:
I want it to check the type of data the user inputted, but the thing is that its a string.
And as I was looking for sources, I thought of eval() but they said they could hack into my computer.
I also resided to isinstance, but it will always result in True ONLY if I'm checking if its a string.
So how can I get the type of a variable in a string type while not using eval()?

Full Code:
class Token:
def __init__(self, type, value):
self.type = type
self.value = value
class Reader:
def __init__(self, text):
self.text = text
def get_tokens(self):
save = ''
tokens = []
for index in range(len(self.text)):
if self.text[index] != ',' and self.text[index] != ' ':
save += self.text[index]
else:
print(self.text[index])
if save == '+':
tokens.append(Token('TT_SYMBOL_PLUS', '+'))
elif save == '-':
tokens.append(Token('TT_SYMBOL_MINUS', '-'))
elif save == '*' or save == '++':
tokens.append(Token('TT_SYMBOL_MULTI', save))
elif save == '/' or save == '--':
tokens.append(Token('TT_SYMBOL_DIVIDE', save))
elif save == '^' or save == '**' or save == '+++':
tokens.append(Token('TT_MATH_EXPONENT', save))
elif save == '=':
tokens.append(Token('TT_SYMBOL_EQUALSIGN', '='))
else:
tokens.append(Token('TT_SPECIAL_UNKNOWN', save))
save = ''
return tokens
class Decoder:
def __init__(self, tokens):
self.tokens = tokens
def decode(self):
updatedtokens = []
for token in self.tokens:
updatedtokens += [token.type, token.value]
return updatedtokens
while True:
cmd = input()
print(Decoder(Reader(cmd).get_tokens()).decode())
