Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to write multiple values to on a row to txt and avoid tuple?

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

(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])}")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading