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:

id=raw_input("Record id: ")
update=raw_input("Note: ")
cursor.execute ("UPDATE notes SET note='"+update+"' WHERE id='"+id+"'""")
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:

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

But how do I add it to the raw_input part?

I hope my question makes sense.

Thank you!

Kind regards,

Recommended Answers

All 3 Replies

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/AnotherTutorial#head-2e6716d7887279f22b0ffa57dc03278ea4ed8f85
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 :) )

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.

I see. Thanks for your replies, guys!

Kind regards,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.