[Tutor] Reading from a GUI
D-Man
dsh8290@rit.edu
Tue, 23 Jan 2001 21:46:07 -0500
On Mon, Jan 22, 2001 at 11:58:16AM +1100, wheelege wrote:
|
| Hi,
|
| Is this what you meant....
|
| PythonWin 2.0 (#8, Oct 19 2000, 11:30:05) [MSC 32 bit (Intel)] on win32.
| Portions Copyright 1994-2000 Mark Hammond (MarkH@ActiveState.com) - see
| 'Help/About PythonWin' for further copyright information.
| >>> a = "first line\nsecond line"
| >>> a
| 'first line\012second line'
| >>> print a
| first line
| second line
|
| From that I gather that the escape code is \012 ?
What is meant by "escape code" can differ by useage. For example, in
Eiffel you would use "%N" as the excape code for a newline. \012 is
the octal value of the character. 0xA is the hexadeciaml value and 10
is the decimal value. In C/C++/Java/Perl and Python \n is used as the
escape for a newline, but with the proper conversion you can use any
of these.
To "read from" a GUI you need to check the docs of the gui you are
using. In GTK, for example, there is a funciton get_text in the
Gtk.Text widget (or some similar name). The function returns a string
object.
import string
my_str = text_widget.get_text()
modified_str = string.replace( my_str, "\n" , "<br>" )
print my_str
pirnt modified_str
The text widget (text_widget) has already been created and bound to
the name. I use the replace() function in the string module to
replace all newlines with "<br>". I probably have the arguments in
the wrong order though. Use the following to find out which order to
use:
import string
print string.replace.__doc__
HTH,
-D