[Tutor] help on newbie program

Nick Jensen njensen@utahfirst.com
Wed May 28 19:30:02 2003


Hello Magnus and thank you for taking time to answer.

I should have been more clear on a few things in my email. Sorry about =
that. Not only have I read the code and example programs, but I did type =
it all out and run the programs on my Linux box. I know I may understand =
the code from just reading it, but won't be able to create anything =
unless I spend time typing it out fiddling with it.

>>Have you tried single-stepping it in a debugger?

Actually, I was wondering if there was a way to follow the program line =
by line as it executed. I didn't know you could do that and I will =
definitely try that now. Thank you for showing me that.

I also apologize for not being more specific about what I don't =
understand. I think my problem was that I really wasn't sure where to =
start explaining what I didn't understand if that makes any sense hehe =
=3D). Lets see if I can take a stab at it...

I've looked over the program in question time and time again, but I =
guess my problem starts with the first line that is executed which is:

run_test(get_questions())

I know run_test function is run, but not sure what (get_questions()) is =
doing for that. I think it is accessing the lists from the get_questions =
function at the beginning, but that is really where I lose track of it.=20

I'm going to try using the debugger right now and see if that helps. I =
just simply lose track of what's goin on right off the bat. Its funny =
too because I had no problem with the other examples in the tutorial for =
lists or functions. Maybe its just a lot more complicated than what I've =
seen up till now.=20

At any rate, I'm going to try single-stepping in the debugger and see if =
that helps me understand more.

Btw, any suggestion for a good book to go through for a python newbie? I =
wanted to try some of the online guides first before I spend money, but =
will eventually need more material.

Thanks for your time...

-Nick

-----Original Message-----
From: Magnus Lyck=E5 [mailto:magnus@thinkware.se]
Sent: Wednesday, May 28, 2003 4:45 PM
To: Nick Jensen; tutor@python.org
Subject: Re: [Tutor] help on newbie program


Hi Nick, and welcome to Python. I hope you will enjoy it.
It's really a rather amazing tool to make thoughts turn
into action. :)

A wise man called Fred Brooks wrote about "the joys of the craft"
in his book "The Mythical Man-Month" almost 30 years ago. See
http://www.davar.net/PROGRAM/EXTRACTS/CRAFTJOY.HTM for his view
of why we like programming.

At 14:49 2003-05-28 -0600, Nick Jensen wrote:
>I have read every example and line of code up to and including the =
section=20
>on lists, but I just cannot understand the last example in that section =

>named test.py.

Are you just reading this, or are you playing interactively
with the interpreter as you go along? Reading is good, but I
don't think there is a better way than to try to improvise at
the python interpreter based on what you read.

Few other languages makes it so simple to do that as Python.

The problem with *only* reading is that there is no way you
can really know how much you learnt. Does it work the way you
think, or do you only think you know how it works? You can never
know that, unless you try to modify the code to do something
different, based on the principles you think you understood,
and...fail. You need to push the limits...and get reality
checks...

Learning programming without really practicing, is like learning
electromagnetic fields and waves without doing the exercises
properly. I tried that, and the exam result was really humiliating. :)

Reading and thinking that you understand just won't cut it.

>I understand parts of it, but not all of it as a whole. I'm not able to =

>follow the flow of the program and whats happening at each step. Maybe =
I'm=20
>asking too much, but was wondering if anyone could walk me through the=20
>code and whats happening. By the way, I did send an email to Josh =
asking=20
>this same question, but not sure if I'll hear back or not and thought =
I'd=20
>ask here just in case. Here it is...

Have you tried single-stepping it in a debugger? In IDLE
for instance. Start IDLE and load the file in question,
Select Debug -> Debugger in the Python shell window to
open the "Debug Control", tick the "Source" checkbox,
activate the editor window with your source code, and
press Ctrl+F5 to start the program. Then use the "Step"
button in the Debug Control to advance one code line a
at time. This will let you follow the way the code is
executed. You will also be able to see the current values
of the objects that are in the current local and global
(it you choose so) scopes. You might get into other
pieces of code during the debugging, at least when the
program asks you for a question. At that point you can
just press the "Out" button in Debug Control to run
until you leave that code. You might also need to manually
switch to the Python shell window to be able to answer
the question when it's time for that. (If the "Step"
button is grey and you don't know understand why you
can't continue, it's probably because you have to answer
a question. Activate the Python shell window, type your
answer followed by pressing the [Enter]-key. (Actually,
now that I tried, I eventually got stuck in the debugger.
Maybe the debugger needs debugging? Anyway, I had already
answered the third question by that time, so I had followed
most of the code.)

Returning to your woes:

What is it you don't understand? We don't want to spend
our own and your time explaining things you already know! ;)

Do you understand what a function is, and how defining a
function is different from calling a function?

Do you understand how functions return values?

Do you understand the concept of scopes and namespaces?

Do you understand the distinction between objects and the
names that refer to ojects?

Do you understand these questions? ;)

>run_test(get_questions())

Do you understand that the above is eqivalent to the code below?

questions =3D get_questions()
run_test(questions)


--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The shortest path from thought to working program=20