Tuesday, 15 May 2012

python - Suppress linebreak on file.write -


While writing a text file, some files. Write examples include a lineback in the output file and other 't. I leave no line breaks, where I tell them. Code:

  for wks.wc.items () in workcases: out.write (doc) # It works fine, there is no linebrick for word in wordlist: if wc In the words: out.write "\ t% d"% wc [word] #linebreaks Others appear: out.write ("\ t0") # After each of these. Write ("\ n") # There were mixed spaces / tabs in this line  

What am I missing?

Update

I should take a clue from the code pasted in SE. For some reasons, the last line contains a mixture of spaces and tabs, such as the Blind in the textmate "outside of the word" ... appears outside the loop - but interpreter Changing the spaces in the loop tab that was being solved solved the problem.

Thank you for your input.

file.write () does not add any new lines if your There is no \ n s in the string written by.

But the word in your word list by using a new line out.write ("\ n") for each, is that what you want?

  for doc, in wc wordcounts.items (): Word.write (doc) # This works fine, there is no lineback for word in the word list: if the word wc: Out.write ("\ t% d"% wc [word]) #linebreaks Others appear: out.write ("T0") # After each of these. Type "NEWLINE" on each writing ("\ n") # & lt; NEWLINE!  

Perhaps you indented out.write ("\ n") too far ???


No comments:

Post a Comment