I would like to write three values on a row in my txt.
My function:
def write_txt(file_name: str, content: str) -> None:
with open(file_name, "a") as text_file:
text_file.write(content + "\n")
But when I insert multiple values into a content (as a tuple) like this:
write_txt("myfile.txt",f"{int(value[0]),int(value[1]),int(value[2])}") I got this in my txt:
(594940819, 1, 0)
(594940820, 1, 1)
(594940822, 1, 1)
But desired output is this:
594940819,1,0
594940820,1,1
594940822,1,1
How can I do this without using multiple replace? Thanks
>Solution :
The problem seems to be in your input:
write_txt("myfile.txt",f"{int(value[0]),int(value[1]),int(value[2])}")
here you are passing the string f"{int(value[0]),int(value[1]),int(value[2])}" that evaluates as a tuple since you have put commas. Correct text:
f"{int(value[0])},{int(value[1])},{int(value[2])}"
Correct statement:
write_txt("myfile.txt",f"{int(value[0])},{int(value[1])},{int(value[2])}")