0

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="")

1
  • 2
    file.write never add a newline... Commented Jun 17, 2019 at 21:55

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.