When you create a Class, you should know how many variables your Class will have.
It is a bad idea to dynamically create new variables for an object in a Class because you can't do operations with variables.
e.g. Suppose your class has variables name
,age
,marks
,address
. You can perform operations on this because you know the variables already.
But if you try to store variables dynamically, then you have no idea which variables are present and you can't perform operations on them.
If you only want to display the variable and its value present in a file, then you can use a dictionary to store the variables with their respective values. After all the variables are stored in the dictionary, you can display the variables and their values:
dict={}
with open('filename.txt') as f:
data = f.readlines()
for i in data:
i = i.rstrip()
inner_data = i.split(',')
variable = inner_data[0]
value = inner_data[1]
dict.update({variable:value})
print(dict)
This will print all the variables and thier value in the file.
But the file should contain variables and values in the following format:
name,Sam
age,10
address,Mumbai
mobile_no,199204099
....
....