new line issue with f.write

Question:

I’m trying to use the f.write keyword, I want each thing I write to be in a new line so I did this:

f.write('',message_variable_from_previous_input,'n')

However, after I ran this it threw back an error saying the following:

Traceback (most recent call last):
  File "c:UsersUser1OneDriveDesktopcodingfolder_namrfile_name.py", line 5, in <module>
    f.write('',msg,'n')
TypeError: TextIOWrapper.write() takes exactly one argument (3 given)

Does anybody know haw to fix this?

Asked By: FV_GR.py

||

Answers:

write method takes exactly one argument

so you should write like this:

f.write(f"{message_variable_from_previous_input}n")

or:

f.write(str(message_variable_from_previous_input) + "n")
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.