Re: How do you program in Python?





anthonyberet wrote:
> My question isn't as all-encompassing as the subject would suggest...
>
> I am almost a Python newbie, but I have discovered that I don't get
> along with IDLE, as i can't work out how to run and rerun a routine
> without undue messing about.
>
> What I would really like is something like an old-style BASIC
> interpreter, in which I could list, modify and test-run sections of
> code, to see the effects of tweaks, without having to save it each time,
> or re-typing it over and over (I haven't even worked out how to cut and
> paste effectively in the IDLE environment).

I think you're missing something about IDLE if you are re-typing.

For example:

IDLE 1.1a3
>>> for i in range(25):
print i,

When you type the above, you get

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

Now let's say you want to re-run that with 10 instead of 25.
You don't have to re-type it. Click to place your cursor anywhere
in the original block of code and hit <return>. Idle will re-type
the entire block for you:

>>> for i in range(25):
print i,

The cursor will be at the very end of the block so you can re-run
it by hitting <enter> twice. But you'll get the same output.
Instead of hitting <enter> twice, use your cursor keys (or mouse)
to move to the 25 in the range function and edit it to 10. Once
edited, move the cursor back to end of the block and hit <enter>
twice to execute

>>> for i in range(10):
print i,


0 1 2 3 4 5 6 7 8 9

It sounds worse than it is, just takes a little getting used to.

Once you're happy with that code fragment, edit it again and add
a definition at the start.

[1] click in the block and hit <enter>, Idle re-types the block

>>> for i in range(10):
print i,

[2] place cursor in front of the 'for' and add a function name
and change the 'for' to use the parameter instead of a constant

>>> def t(n): for i in range(n):
print i,

[3] hit <enter> (here we do want to insert a line) and IDLE will
show you this (indents adjust automatically)

>>> def t(n):
for i in range(n):
print i,

[4] move cursor to the end of the block (after the comma)
and hit <enter> twice

Nothing happens. You have defined a function, but did not execute
it. To execute it, type its name with some value of n.

>>> t(8)
0 1 2 3 4 5 6 7

Now you can try it out with different values of n without having
to edit the whole block. Now if you want to change the function
definition, say we want each number output on a seperate line,
do the same thing we did before. Click anywhere in the block and
hit <enter>. The entire block is re-typed for you. Make your change
(remove the comma) and hit <enter> twice.

>>> def t(n):
for i in range(n):
print i

Again, the function is not executed. And you can always simply
click on the previously typed line t(8) and hit <enter> twice

>>> t(8)
0
1
2
3
4
5
6
7



>
> I see lots of alternate IDEs etc, but which would allow me the simple
> interface that I have described? - I really don't know about IDEs in
> general, and I suspect I would be out of my depth with one of those.
>
> Thanks, and feel free to mock ;)

.



Relevant Pages

  • Re: Stuck! Little Help Plz K Thx
    ... I couldn't hit him worth *anything*, and he sure as heck could hit ... ascend, TP back to the 1st staircase, and leave. ... him to chase you several paces away from the stairs. ... Move the cursor up 4 spaces ...
    (rec.games.roguelike.adom)
  • Re: Probability to ponder...
    ... "Wayne Vinson" wrote in message ... twice in a row are slightly worse than 40,000:1 against. ... opportunity to have aces hit twice. ... that aces will hit for the next two hands. ...
    (rec.gambling.poker)
  • Re: Great SWT Program
    ... cursor to a line within the grep buffer and have emacs instantly move ... moving your cursor to a line and pressing ... meaning that you have to hit another key after down-arrow ...
    (comp.lang.java.programmer)
  • Re: Hit the ball twice
    ... He would be given out "hit the ball twice" if he tried ... to score a leg bye that way because no shot would be offered. ... the bat to gain a leg bye he would be out hit the ball twice. ...
    (uk.sport.cricket)
  • Re: Multi-line comments
    ... If I gotta find and do control something twice to mark it and twice to unmark it and heck ctrl-k and ctrl-c would probably take both hands. ... it takes one hand and I only have to move my thumb up or down a tad to hit ctrl or shift while using my index finger for insert. ...
    (microsoft.public.dotnet.languages.vb)