cs0815
cs0815

Reputation: 17418

number printed to console when writing to file

I am using this code to write a dictionary to the file system as tab separated file:

with open("C:/bla/bla.txt", "w", encoding="utf-8") as f:
    for key, value in some_dictionary.items():
        f.write("%s\t%s\n" % (key, value))

not only does it crash my IDE (in this case Visual Studio) but it also writes stuff to the console. Not sure why? IMHO the code above is OK and should simply write to the file system. Thanks!

Upvotes: 0

Views: 840

Answers (1)

basrican şen
basrican şen

Reputation: 76

with open("C:/bla/bla.txt", "w", encoding="utf-8") as f:
    for key, value in some_dictionary.items():
        a = f.write("%s\t%s\n" % (key, value))

You can assign the result like this to avoid printing console, as said in: How to prevent f.write to output the number of characters written?

Upvotes: 5

Related Questions