473,545 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

paste text with newlines into raw_input?

Using Python on Debian Etch.

What is the best way to paste a block of text in at the command

I'm trying something like:

Quote = raw_input("Past e quote here: ")

Which works great for one line of text with a single newline. It gets
stripped. Okay.

Is there a way to paste in a block of text that has multiple lines and
newlines? I don't care if they all get stripped in the process, in
fact I'd prefer it. I've used strip before, but that doesn't seem to
work until you get the text into the program.

Thanks for any help.


May 30 '07 #1
4 5424

print "paste quote:"
emptycount = 0
lines = []

while emptycount < 2:
t = raw_input()
if len(t) == 0:
emptycount +=1
lines.append("\ n")

quote = " ".join(line s[:-3])

print "Quote was this:"
print "============== ="
print quote
print "============== ="

May 31 '07 #2
On May 30, 2:04 pm, BartlebyScriven er <bscrivene...@g mail.comwrote:
Using Python on Debian Etch.

What is the best way to paste a block of text in at the command

I'm trying something like:

Quote = raw_input("Past e quote here: ")

Which works great for one line of text with a single newline. It gets
stripped. Okay.

Is there a way to paste in a block of text that has multiple lines and
newlines? I don't care if they all get stripped in the process, in
fact I'd prefer it. I've used strip before, but that doesn't seem to
work until you get the text into the program.

Thanks for any help.

import sys
s =sys.stdin.read ()
print s

which will read until ctrl-d


May 31 '07 #3

I think I need a Tkinter text entry widget, but it will take me a week
to learn how to set it up.

I'll report back.


May 31 '07 #4

I'm going to post this here in case somebody else searches for an
example Tkinter Text Widget for entering multiline text. I don't like
GUI and don't even quite understand how it works, but it seems to
work. In my case it's part of a program for pasting a quote from the
clipboard into a MySQL database (hence the separate paste button).

I also don't know OO and Classes. If someone wants to wrap it in a
class and repost it could save the free world.

Or suggestions for making it better much appreciated.



#! /usr/bin/python
import Tkinter
import tkFont
Tkinter Text Widget for entering multline text.
Rick Dooling http://dooling.com

Based on:

Alan Gauld's "GUI Programming with Tkinter"

Jeff Eppler's clp post - 3 August 2005
"cut and paste text between Tkinter widgets"

# the first two functions come from Jeff Eppler's post
def make_menu(w):
global the_menu
the_menu = Tkinter.Menu(w, tearoff=0)
the_menu.add_co mmand(label="Cu t")
the_menu.add_co mmand(label="Co py")
the_menu.add_co mmand(label="Pa ste")

def show_menu(e):
w = e.widget
the_menu.entryc onfigure("Cut",
command=lambda: w.event_generat e("<<Cut>>"))
the_menu.entryc onfigure("Copy" ,
command=lambda: w.event_generat e("<<Copy>>") )
the_menu.entryc onfigure("Paste ",
command=lambda: w.event_generat e("<<Paste>>" ))
the_menu.tk.cal l("tk_popup", the_menu, e.x_root, e.y_root)

def evClear():
eText.delete(0. 0,Tkinter.END)

def assign():
# get text from the text widget and assign it to Quote
Quote = eText.get(0.0, Tkinter.END)
# just for testing the assignment
print Quote

def paste():
eText.event_gen erate("<<Paste> >")

t = Tkinter.Tk()

# create the top level window/frame
F = Tkinter.Frame(t )
F.master.title( "Enter Quote ")
F.pack(expand=" true")

myfont = tkFont.Font(fam ily="Courier", size=14)

# frame for message to the troops
fMessage = Tkinter.Frame(F , border=1)
fMessage.pack(s ide="top", expand="true")
lMessage = Tkinter.Label(f Message, text="Paste your quote into the
Text Box from the clipboard, or type it in. When you are finished,
click Enter.")
lMessage.pack(e xpand="true")

# frame for text entry field
fText = Tkinter.Frame(F , border=1)
fText.pack(side ="top", expand="true")
# the text widget
eText = Tkinter.Text(fT ext, width= 75, height=20, font=myfont,
wrap=Tkinter.WO RD); eText.pack(side ="top")
eText.bind_clas s("Text", "<Button-3><ButtonReleas e-3>", show_menu)

# frame with the buttons
fButtons = Tkinter.Frame(F , relief="groove" , border=3)
# the buttons
bPaste = Tkinter.Button( fButtons, text="Paste", command=paste)
bPaste.pack(sid e="left", padx=15, pady=4)
bEnter = Tkinter.Button( fButtons, text="Enter", command=assign)
bEnter.pack(sid e="left", padx=15, pady=4)
bClear = Tkinter.Button( fButtons, text="Clear Text", command=evClear )
bClear.pack(sid e="left", padx=15, pady=4)
bQuit = Tkinter.Button( fButtons, text="Quit", command=F.quit)
bQuit.pack(side ="left", padx=15, pady=4)
# pack them
fButtons.pack(s ide="bottom", expand="true")



May 31 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: in_file = raw_input("What is the name of the file you want to open: ") in_file = open("test.txt","r")
by: Sam Quigley | last post by:
Hi, I want to use XSL to wrap paragraphs of text in <p> tags automatically, basically using the heuristic that two chunks of text separated by 2 consecutive newlines are to be treated as two <p>s... I do this right now by putting the input xml (the text to be wrapped) in a <paraset> tag, and using the following XSL: <xsl:template...
by: wtnt | last post by:
Hello. I've searched all over and haven't seen another thread with this problem. Please bear with me as I try to explain. thanks. :) I have some programs that need to be cross-platform compatible (unix and windowsXP). The first program parses a text file and records where snippets are in terms of where it begins (char offset from begin of...
by: spectre | last post by:
Hi, I need to copy/paste texts form word, notepad... to an html textarea to store it into a database. With the <pre>tag, and a text with long lines, the text displayed in the textarea needs to be scrolled horizontaly within the browser window: I can't succeed in stopping the text to be larger than the <table>;<tr>;<td> settings.
by: sonald | last post by:
Hi, Can anybody tell me how to change the text delimiter in FastCSV Parser ? By default the text delimiter is double quotes(") I want to change it to anything else... say a pipe (|).. can anyone please tell me how do i go about it?
by: Steve | last post by:
Hi, I've created a Python program that a user enteres one line of text which will then create an acronym from that text. What I want to add to the program is the abilty to rerun this process (where the user enteres another line of text) until the user has had enough and enters a blank line which would then end the program. Can anyone...
by: Collin | last post by:
I'm pretty new to Python, but this has really bugged me. I can't find a way around it. The problem is that, when I use raw_input("sajfasjdf") whatever, or input("dsjfadsjfa"), you can only have numerical values as answers. Any help would be appreciated. Thanks.
by: nick777 | last post by:
Hope the Community can bear with me as I muddle with the vocabulary since I am not really sure if I am going about this the correct way. My question is as follows: If I had some sample data in the form of delimited text, in this case comma-delimited (eg. canned_data.txt) and the format looked roughly like this: name,age,occupation,status...
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...
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...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
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...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
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...
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...
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: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.