471,058 Members | 1,028 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,058 software developers and data experts.

removing line breaks

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
2 25935
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
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.

Similar topics

5 posts views Thread by Mechphisto | last post: by
6 posts views Thread by Aaron Collins | last post: by
1 post views Thread by ChrisC | last post: by
2 posts views Thread by Mike | last post: by
13 posts views Thread by scorpion53061 | last post: by
18 posts views Thread by mouseit101 | last post: by
5 posts views Thread by joelbyrd | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.