[Tutor] Language truce

Michael Powe michael@trollope.org
Thu, 28 Jun 2001 12:40:31 -0700


>>>>> "Danny" == Danny Yoo <dyoo@hkn.eecs.berkeley.edu> writes:

    Danny> On Thu, 28 Jun 2001, Michael Powe wrote:

    >> A couple things I mentioned, like you can't increment through
    >> loops.

    Danny> I'm a little confused by what you mean by "incrementing
    Danny> through loops".  Can you give an example of what you mean?

The standard C (for i=0; i < n; i++), which uses the increment
operator (i++) which is not present in python.  I'm sure there must be
some discussion somewhere about why the decision was made to leave
this out, I just have not come across it.

Yes, as someone else points out, you can use range(), but obviously
that is not the same thing. (In some cases, it may be functionally
equivalent and maybe that is the point.)  Also, maybe it's just me,
but I consider

k = k+1

as a loop counter to just be unacceptably clumsy.  Forcing me to use
that construct tells me that I should not be designing my program that
way. 

    >> But, also, it occurs to me that another part of the paradigm
    >> appears to be that you can't create new data types, aka structs
    >> in C.

    Danny> We can make new data types work in by using classes.  For
    Danny> example, if we want to make a Balloon class that has a
    Danny> shape and color, we can do the following:

    Danny> ### class Balloon: def __init__(self, shape, color):
    Danny> self.shape, self.color = shape, color ###

Ah, yes.  I should have realized, we just started going over classes
in my java course last night.  

My 'teach-yourself-python' project is an address book.  I happen to
need one and I don't like anything that's already available.
Unfortunately, the python books just aren't making it as instructional
tools.  I know quite a bit about python syntax &c and practically
nothing about actually writing programs in python.  Anyway, I have the
data entry part and the write-to-file parts completed -- that was
easy.  But, the file-reading and data storage parts are more
interesting.  In C, I would just use a struct and a linked list and
write/read the structs to/from a binary file -- I've done all that
type of stuff before.

I had just about determined to use dictionaries with tuple keys for
reading in the data (even though that seems complicated to me).
Deleting entries from the book becomes an issue, though.  Also,
there's issues with duplicate names.

A class is probably the way to go.  Might be a little while before I
get a handle on that, though.

    Danny> Hope this helps!

Yep, thanks!

mp

-- 
  Michael Powe                                 Portland, Oregon USA
'Unless we approve your idea, it will not be permitted, it will not be
allowed.'  -- Hilary Rosen, President, Recording Industry Association
of America