By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,758 Members | 1,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,758 IT Pros & Developers. It's quick & easy.

removing line breaks

P: 2
i was trying to code a morse code decipherer which workd fine except that the .txt file that i was converting had linebreaks built in, i cant get python to ignore the line breaks and i cant find any characters for line breaks to remove them using the string.replace() function

if anybody know the syntax for a line break or the ASCII characters that can be used for line breaks to replace/remove them that would be great

or if anybody know how to read multiple lines as a single uninterrupted string that would be even beetter


PS i have tried for line in file() and then string = string+line and this still creates line breaks in the string even though it is a single string
Jul 12 '06 #1
Share this Question
Share on Google+
2 Replies

P: 2
solved it, just in case anyone else was wondering if reading from a text file for example use the following

for line in file(filename):
print string

at this point string is a single uninterrupted string you can work with

Jul 18 '06 #2

P: 12
Expand|Select|Wrap|Line Numbers
  1. print ''.join(open('the_file.txt').read().splitlines())
Jul 20 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.