0

I have a function that can only accept strings. (it creates the image with the string, but the string has little formatting and no word wrapping, so a long string will just bleed right through the edge of the image and keep going into the abyss, when in reality I would have liked it to create a paragraph, instead of a one line infinity).

I need it print with line breaks. Currently the file is being readin using

inputFiles.readlines()

so that this reads the entire file. Storing file.readLines() creates a list. So this list cannot be passed to my function looking for a string.

I used

inputFileContent = ' \n'.join(inputFiles.readLines())

in an attempt to force hard line breaks into the string between each list item. This does not work (edit: elaboration here) which means that the inputFileContent string does not have line breaks even though I put '\n' between the list elements. From my understanding, the readLines() function puts the individual lines into individual elements of a list.

any suggestions? Thank you

4
  • 1
    What is inputfiles? What does "does not work" mean? Commented May 18, 2011 at 23:12
  • 1
    Please explain what you mean by it doesn't work. Show what it does and what you want it to do. Commented May 18, 2011 at 23:12
  • Please give information about the function you are calling. Is it part of a library? How is it documented to work? Commented May 18, 2011 at 23:13
  • I opened my input file in vi and noticed there are ^M where all the line breaks should be. How can I make python notice these too, currently it sees the entire file as one line. Commented May 19, 2011 at 13:31

2 Answers 2

4

Use inputFiles.read() which creates a string. Does that help?

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

2 Comments

Hey, there are worse things in life.
Yeah, like us both not making the next python meeting because it was booked before you replied... Oh, wrong chat window...
2

The 'join' should have worked. Your problem may be that the writing of the string ignores newline characters. You could maybe try '\r\n'.join(...)

2 Comments

adding \r to the mix didn't do anything either, I just tried using "readLine()" to see if it was distinguishing and to my surprise, python is not seeing the hard returns within my inputFile
I got it working, my file needed to be read in with the U flag. Then python recognized the hard returns within the file.

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.