Python Forum
Saving the results from an input in a txt. file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Saving the results from an input in a txt. file
#1
Im currently working on a school project where I have to make a multiplication table where you put in a value for the size you want the table to be. I want my program to save the results to "gangetabell.txt", but I cant seem to figure out how to save the results to the file. My problem is how to put the code as an argument inside the write() function.

Here is the code:

print("\t\tGangetabell\n")

n =int(input('Vennligst skriv inn et tall: '))
for row in range(1,n+1):
for col in range(1,n+1):
print(row*col, end="\t")
print('\n')
saveFile = open('gangetabell.txt', 'w')
saveFile.write()
saveFile.close()



And this is the error I get:

Traceback (most recent call last):
File "C:/Users/Erlend/PycharmProjects/python_2/oppg_2.py", line 9, in <module>
saveFile.write()
TypeError: write() takes exactly one argument (0 given)

Process finished with exit code 1
Reply
#2
Since you have no indentation, it is hard to determine what your code actually looks like.  However, the "error" code is pretty explicit. You are trying to write to a file without saying what it is you want to write.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
file_object.write("You put here what you want to be written into the file.")
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help implementing an input with file operations Gaijin 3 2,086 Jun-08-2022, 05:50 PM
Last Post: Gaijin
  Changing the content of the table and saving the new data into another file femke_pythonquestion123 1 1,582 Sep-18-2020, 12:06 PM
Last Post: femke_pythonquestion123
  how to add the user input from file into list wilson20 8 4,340 May-03-2020, 10:52 PM
Last Post: Larz60+
  Saving to Json file Shambob1874 1 2,471 May-30-2018, 10:00 PM
Last Post: micseydel
  Saving an numpy.ndarray as .ply file in python Tina 4 17,104 Oct-11-2017, 06:08 PM
Last Post: Tina

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020