473,791 Members | 2,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

removing line breaks

2 New Member
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

caspar

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 26443
caspardh
2 New Member
solved it, just in case anyone else was wondering if reading from a text file for example use the following

string=""
for line in file(filename):
string+=line.re place("\n","")
print string

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

caspar
Jul 18 '06 #2
dvs
12 New Member
Expand|Select|Wrap|Line Numbers
  1. print ''.join(open('the_file.txt').read().splitlines())
Jul 20 '06 #3

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

Similar topics

5
2271
by: Mechphisto | last post by:
I'm using a textarea to insert some notes into a database. It's inserting the complete result into the mySQL table including the linebreaks...and not as a visible symbol but an actual linebreak. If I select the fireld in mySQL at a command prompt, the results take an inordinate amount of space from all the linebreaks. I tried nl2br() before it goes into the INSERT, but all that does is ADD <br /> to the data but it still have linebreaks...
6
2971
by: Aaron Collins | last post by:
Hello, i have a string that was entered in a web form and stored in a mysql database where the user entered carriage returns as well as <br>'s after each line in the form. the data is stored as line 1<br> line 2<br> line 3
1
346
by: ChrisC | last post by:
Im having trouble removing line breaks from my c# string. Actually, im having trouble getting .Trim() to work properly, as it seems to count a string that has nowt but a break of some sort as not being empty. To get trim to work properly im trying to axe out the line breaks seperately. Ive got .replace("/r") and "/n" but still having problems with some strings. Are there paragraph markers or something I should be removing too? how do i...
4
22772
by: intl04 | last post by:
I have a memo field that is included in some Access reports I created. Is there some way for the memo field to display nicely formatted text, with line breaks between paragraphs? Or is it necessary to export the report? I tried exporting a report by using the .rtf rich-text format (the plain-text format was the only other word-processing option listed when exporting). I then opened the .rtf file in Word. However, it looks like some...
2
13203
by: Mike | last post by:
I need my textbox to work more smoothly with respect to line breaks. When I have data pulled from the database into a textbox there are hard line breaks at the end of each line (by definition how Lines property works, right?). But, the textbox is used for editing data previously entered into the database. Ideally, what I want is just a hard break at the end of each paragraph so users can smoothly enter or remove data anywhere without...
13
1302
by: scorpion53061 | last post by:
This is really weird. I have provided to a client a means for which they can store text in a database and insert into a word document. Originally they entered the text into a textbox. However when they copied and pasted text in there apparently formatting symbols came over as well but they were not visible. So when they searched for this text in the document after inserting it the "find" function didnt work.
18
1594
by: mouseit101 | last post by:
I'm writing a program to emulate nuerons (can't spell for my life sorry) and am using an array of "mailboxes" to propagate messages through the network, but I need to be able to remove the request from everybody's mailbox after the response is returned. The source can be found at www.birchile.com/webbomb/brain.htm , the source is in the only script tag there. To be specific I want to delete text from the mb array using the look() method...
5
16852
by: joelbyrd | last post by:
Didn't know exactly where to post this, but: How do I get line breaks in a textarea? I'm pulling text from a database, and this text definately has line breaks in it, because I replaced all the line breaks with <br /> tags ( using the php function nl2br() ), and <br /> tags showed up in the textarea.
8
41785
Chittaranjan
by: Chittaranjan | last post by:
Hi All, I am using perl to get the data from the form fields and I have a text area from where if some one enters data like below: "This is test And this is also test This is also test." So here you can notify the text is entered with hitting of enter key to have the line break. But I am having the problem while saving the data entered in this field in a text file then there also it is saving with these line breaks(new lines) so if am...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5430
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4109
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.