1

I'm trying to write some lines in a file.

My problem arises in the output.

The code looks like this:

fileInput = open("file.txt","r+")
fileOutput = open("fileOut.txt","w")
for line in fileInput.readlines():
   outputString = functionname+"="+otherfunctionname+str(lineNumber)
   fileOutput.write(outputString)
   fileOutput.write("\n")

The expected output:

function()=name=123
function1()=name1=1223

Instead the output looks like this:

function()
=name=123
function1()
=name1=1223

I can't figure out what is the problem. Can you give me a hint of what it could be ?

4
  • 1
    Where are you creating otherfunctionname ? How are you creating it? Commented Sep 10, 2015 at 10:37
  • I'm creating it by parsing the line(before creating outputstring), I gave a general case Commented Sep 10, 2015 at 10:39
  • 2
    probably functionname ends with a new line, strip that off. Commented Sep 10, 2015 at 10:40
  • "file.txt" which element are stand? Commented Sep 10, 2015 at 10:44

1 Answer 1

1

Try outputString = functionname.rstrip()+"="+otherfunctionname+str(lineNumber)

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.