Re: [Tutor] YATENJoe

2005-05-17 Thread Andrei
Joseph Quigley  gmail.com> writes:

> Is there a way of telling Python to make a new line after you press Enter
(return)?

Return automatically ends the current input line (and therefore starts a new
one) when you use raw_input.

>> I would suggest that you learn a bit more about Python's facilities before
>> embarking on an ambitious project :) - you won't get very far without knowing
>> how to use lists and dictionaries.

> So that's one of the ways Dicts, and lists are used for? I never could fully
grasp their use.

Perhaps you should have a look at "How to think like a computer scientist in
Python" (http://www.ibiblio.org/obp/thinkCSpy/). Chapters 8 and 10 discuss Lists
and Dictionaries
  http://www.ibiblio.org/obp/thinkCSpy/chap08.htm
  http://www.ibiblio.org/obp/thinkCSpy/chap10.htm ,

but I'd recommend you read all of it (or another Python tutorial).

Yours,

Andrei

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] YATENJoe

2005-05-17 Thread Joseph Quigley


If you intend to make a text
editor (something which allows the user to browse
through the text and manipulate it at will) using just raw_input and
print, I
think you've set yourself an impossible task. For a console editor you
should
probably look at curses
(http://www.amk.ca/python/howto/curses/)
- which don't
work on Windows, so you'll probably need this:
http://adamv.com/dev/python/curses/
(but according to the site it's incomplete).
Ok.
lines = []
while True:
    lines.append(raw_input(''))
(But that offers no way to e.g. save and continue.)
Ok again.
Text editors are IMO not applications suitable for learning vanilla Python, or
OOP for that matter. Text editors are used as example applications in the RAD
IDE world (VB, Delphi and such) because in those environments a text editor is
literally three clicks away (click on memo component, click on form, click on
run). Vanilla Python has no GUI, so no memo component - hence my recommendation
for Tkinter or wxPython. PythonCard and Boa provide an experience somewhat
similar to commercial RAD IDE's if that's what you're looking for.
I got my idea from looking at Nano, Vi, Joe and a few other UNIX text editors. Nano and Joe are console programs. That's why I thought I would try a console ed. in Python.

Having one function for each line is a bad idea whether you code it by hand or
automatically
Ah.
A function implements certain behavior. Having the same behavior (raw_input)
implemented separately for each line is an extremely wasteful way of
programming.
Is there a way of telling Python to make a new line after you press Enter (return)?
I would suggest that you learn a bit more about Python's facilities before
embarking on an ambitious project :) - you won't get very far without knowing
how to use lists and dictionaries.
So that's one of the ways Dicts, and lists are used for? I never could fully grasp their use.
Thanks,
JQ

---
Proud to be a true hacker
(You may have a bad impression of the word "hacker". Do some homework,
go to: http://catb.org/~esr/faqs/hacker-howto.html and become enlightened) 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] YATENJoe

2005-05-17 Thread Andrei
Joseph Quigley  gmail.com> writes:

> I want to make a text editor. I know that there are hundreds out there,
> but practice makes perfect, and I need the practice. My problem is
> that I have no idea how to make one. I've tried a little already by
> defining line functions:def line1():l1 =
> raw_input("")

If you intend to make a text editor (something which allows the user to browse
through the text and manipulate it at will) using just raw_input and print, I
think you've set yourself an impossible task. For a console editor you should
probably look at curses (http://www.amk.ca/python/howto/curses/) - which don't
work on Windows, so you'll probably need this:
http://adamv.com/dev/python/curses/ (but according to the site it's 
incomplete). 

It's probably better to select a GUI toolkit which has an editor widget and
build your editor on that. Tkinter and wxPython both offer this, with wxPython
including a wrapper of the excellent Scintilla control (it has syntax
highlighting, word wrapping, support for non-monospaced fonts, etc.). You could
even write a webbased editor using the text entry widget provided by browsers
(crappy as it may be), even that would be better than hand-coding your own
editor widget.

> line2()Of course, this only allows for 2 lines. What's the trick to an
> infinite number of lines?

lines = []
while True:
lines.append(raw_input(''))

(But that offers no way to e.g. save and continue.)

> YATENJoe"? I'm still a newbie to python (actually OOP programming in
> general!) so I can't have a lot of complicated stuff thrown in my
> face.

Text editors are IMO not applications suitable for learning vanilla Python, or
OOP for that matter. Text editors are used as example applications in the RAD
IDE world (VB, Delphi and such) because in those environments a text editor is
literally three clicks away (click on memo component, click on form, click on
run). Vanilla Python has no GUI, so no memo component - hence my recommendation
for Tkinter or wxPython. PythonCard and Boa provide an experience somewhat
similar to commercial RAD IDE's if that's what you're looking for.

> I thought of a function that would define a function for me. Is this
> possible? If it is how would I do it? If it possible, here's my

Having one function for each line is a bad idea whether you code it by hand or
automatically (yes, it would be possible, but not something you should want to
do). A line of text is a piece of *data* similar to the line before it and the
line after it. 
A function implements certain behavior. Having the same behavior (raw_input)
implemented separately for each line is an extremely wasteful way of
programming. Use data containers (like lists) for storing data and use a single
function for manipulating any item (line) in such a data structure. E.g. let's
say you have 5 lines of text and you want to uppercase them all. Your way would
be to create 5 separate functions (or 1000 if there are more lines) for each
of the lines and call each of those. A better way would be to have a single
function and call that repeatedly telling it on which line to operate.

I would suggest that you learn a bit more about Python's facilities before
embarking on an ambitious project :) - you won't get very far without knowing
how to use lists and dictionaries.

Yours,

Andrei

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] YATENJoe

2005-05-16 Thread Joseph Quigley


YATENJoe (Yet Another Text Editor, Named Joe)
First off, If this isn't the right place to ask, tell me so. That way I
won't make this mistake again :-)
I want to make a text editor. I know that there are hundreds out there,
but practice makes perfect, and I need the practice. My problem is
that I have no idea how to make one. I've tried a little already by
defining line functions:
def line1():
l1 =
raw_input("")
def line2():
l2 =
raw_input("")
line1()
line2()
Of course, this only allows for 2 lines. What's the trick to an
infinite number of lines?
Event driven programming is a must, obviously. How can I use 'Ctrl' + 'Q'
to quit while still being able to type: "Press 'Ctrl' + 'Q' to quit
YATENJoe"? I'm still a newbie to python (actually OOP programming in
general!) so I can't have a lot of complicated stuff thrown in my
face.
I'd like it to not be platform specific, but if it has to be OS bound to
be simple, then that's fine.
I thought of a function that would define a function for me. Is this
possible? If it is how would I do it? If it possible, here's my
idea:
def makefunc():
    # This is where it defines a function. If line1 =
"full" then
    # make a new line adding 1 integer do separate it from
the first.
    def l1():
l1 =
raw_input("")
line1 =
"full"
    l1()
makefunc()
One other thing, is there a way to call a function that is inside
a function? 'Cause
makefunc().l1() doesn't
work.
Thanks in advance,
JQ
PS: FYI  I use Windows XP Pro and Linux
PPS. FYI 2: I'm still a newbie to Linux too :-) 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor