0

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:\Users\User1\OneDrive\Desktop\coding\folder_namr\file_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?

MisterMiyagi
  • 44,374
  • 10
  • 104
  • 119
  • 1
    You have to give only one string – Sheyteo Nov 29 '22 at 17:22
  • modify `f.write('',message_variable_from_previous_input,'\n')` to pass a single string - currently you're passing 3 – Adam Smooch Nov 29 '22 at 17:22
  • `.write()` doesn't take multiple parameters - perhaps you're thinking of how `print()` works, but that's a feature specific to that function. Either concatenate the three items with `+`, or use three separate `.write()`s. – jasonharper Nov 29 '22 at 17:23
  • You could form 1 string from the 3 for example ```f'{message_variable_from_previous_input}\n'``` – Sheyteo Nov 29 '22 at 17:23

1 Answers1

2

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