Insert text in raw_input

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2008
Posts: 11
Reputation: dmpop is an unknown quantity at this point 
Solved Threads: 0
dmpop dmpop is offline Offline
Newbie Poster

Insert text in raw_input

 
0
  #1
Aug 8th, 2008
Hello,

A complete Python newbie needs help. :-) I have a simple script that updates the 'note' field in a MySQL database table based on the record's id:

  1. id=raw_input("Record id: ")
  2. update=raw_input("Note: ")
  3. cursor.execute ("UPDATE notes SET note='"+update+"' WHERE id='"+id+"'""")
  4. print "\nRecord has been updated."

The problem with this solution is that the user must enter everything from scratch. What I'd like to do is to allow the user to edit the current contents. For example, if the 'note' field contains the string "Monkey loves banana", the input field would look like this:

Note: Monkey loves banana

and the user can then edit this string. I can easily obtain the contents of the record using the following code:

  1. row = cursor.fetchone ()
  2. contents = row[1]

But how do I add it to the raw_input part?

I hope my question makes sense.

Thank you!

Kind regards,
Dmitri
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 984
Reputation: Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough 
Solved Threads: 222
Gribouillis's Avatar
Gribouillis Gribouillis is offline Offline
Posting Shark

Re: Insert text in raw_input

 
0
  #2
Aug 8th, 2008
A simple way to do this would be to write a small GUI code, using the wx.TextEntryDialog widget.
I suggest that you visit this link http://wiki.wxpython.org/AnotherTuto...03278ea4ed8f85
and paste the code section just below, and then drop most of the methods, but the method def textentry . In the text entry, you can edit your record.
I think it's an easy solution since the code is ready to run (you may have to install wxpython )
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,072
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 268
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is

Re: Insert text in raw_input

 
0
  #3
Aug 8th, 2008
I think your best bet would be to simply print the value of contents and then ask the user for a new value. Otherwise you will need to figure out how to prompt for input and then subsequently write to the stdin ... you can access stdin/stdout via sys.stdxxx, which will allow you to use write, read, etc. Perhaps you can make use of those to create a custom text input function.
1. Use Code Tags.
2. Homework? Show Effort.
3. Keep discussions on the forum: no PMs
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 11
Reputation: dmpop is an unknown quantity at this point 
Solved Threads: 0
dmpop dmpop is offline Offline
Newbie Poster

Re: Insert text in raw_input

 
0
  #4
Aug 8th, 2008
I see. Thanks for your replies, guys!

Kind regards,
Dmitri
Last edited by dmpop; Aug 8th, 2008 at 9:16 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1150 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC