Mohannad
Mohannad

Reputation: 93

How to write to a text file without adding new line

How to do the following code, but to a text file instead of printing to console.

print("test",end="")

I tried to execute this code, but its not working.

file.write("test",end="")

Upvotes: 0

Views: 46

Answers (1)

Andreas Hell
Andreas Hell

Reputation: 26

file.write() can't accept more than 1 argument (which is the string that should be written to the file)

with open("test.txt", "w+") as file:
    for i in range(10):
        file.write("test")

The result in test.txt: testtesttesttesttesttesttesttesttesttest

Upvotes: 1

Related Questions