I need to create a file to save some variables; I have this
# variables
A = 2
B = 34
C = "foo"
file = open("filename.txt", "w")
file.write(A, "/", B, "/", C)
file.close()
However, I'm not sure is this is the best way, or at least, the best 'Pythonic' way to write in a file. I do not neither know if /
is the best item to disjoin to then read it or it is better to do for example
file.write(f"A={A}/nB={B}/nC={C}")
That is the princiapl problem: I do not know how to, after writing, read multiple variables and its best way to do that. In the reading file, I would like to have something like this:
file = open("filename.txt", "r")
# reading variables
# variables initialized: A=2, B=34, C="foo"
So, to recap, I would appreciate some help to find out:
1) Best format to write in a file
2) How to read multiple variables in that file and initialize them
P.D: it doesn't have to be a .txt
but it's the default format I'm advised to use.
Thank you!