[Tutor] Language truce

Remco Gerlich scarblac@pino.selwerd.nl
Fri, 29 Jun 2001 01:15:49 +0200


On  0, Michael Powe <michael@trollope.org> wrote:
> >>>>> "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.

It's simple. Assignment isn't an operator in Python, and operators can't
change bindings.

It's not possible to write a function inc(x) in Python, since a function
can't change the local binding 'x'.

It would be possible to make keywords "inc" and "dec", and introduce
statements "inc x" and "dec x", but that would be overkill for something
that can just as easily be spelled "x = x+1", or even "x += 1" nowadays.
Needless special casing.

> 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.

Get over it. Sheesh. (well ok, it probably means you should be using range()).


(snip)
> 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.

Reading the file is simply the opposite of writing to it. You might also
want to pickle your classes, or read C structs using the struct module. I
don't know what your problem is exactly.

-- 
Remco Gerlich