Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Having problems while creating a text editor using python

So hello everybody.
I recently had a problem which I tried to use python included file functions and stuff
i tried making a text editor which was when i encountered a problem

i tried to make the txteditor like this:

one = input()
two = input()
three = input()
four = input()
five = input()
six = input()
seven = input()
eight = input()
nine = input()
ten = input()
f= open("guru99.txt","w+")
for i in range(10):
     f.write(one, two, three, four, five, six, seven, eight, nine, ten)
f.close()

but it give the error :
f.write(one, two, three, four, five, six, seven, eight, nine, ten)
TypeError: TextIOWrapper.write() takes exactly one argument (10 given)
can aanybody help with this?
here is the pic

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You’re passing in each number as a separate argument to f.write(), except that function only expects a single parameter.

You can do this by first joining all your inputs into a single variable, such as a string, and then passing that in. This is called concatenation:

joinedInputs = one + two + three + four + ... + ten
f.write(joinedInputs)

However, this is a somewhat inefficient way of doing it, and you may want to research something like a list:

inputs = []
for i in range(10):
    userInput = input()
    inputs.append(userInput)

Then you can simply loop over all of them and join them to a single string, which can be done a few ways, for example by looping over each element in the list and concatenating it as above.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading