[Tutor] Truckers Log....Me Again

Kalle Svensson kalle@gnupung.net
Mon, 21 Jan 2002 07:31:30 +0100


[Erik Price]
> Hello everyone,
> 
> This is my first post to the list. [...]

Welcome!

> On Sunday, January 20, 2002, at 11:53  PM, Danny Yoo wrote:
> 
> >It sounds like you want to do something like the following pseudocode
> >
> >##
> >while 1:
> >    read the input x
> >    if x == yes:
> >        do this
> >    elif x == no:
> >        do the other thing
> >    else:
> >        print some warning
> >###
> 
> Admittedly, I am new so I don't know anything.  But it would seem to me 
> that this "while" loop would never end, since the condition "1" 
> evaluates to "true" infinitely.  I would assume that this is for the 
> sake of example, and not to demonstrate an actual program's pseudocode.  
> But on this list I have seen more than one example use this convention.  
> Is Python different from other languages in this respect?

No, you're right.  There would have to be a "break" somewhere in the
real code, or there would be an infinite loop.  The break statement is
used to exit loops, like:

while 1:
    x = raw_input("Break loop? (y/n)")
    if x in ("y", "Y"):
        print "Yes!"
        break
    else:
        print "No!"
print "y entered!"

> Another question I have is about objects.  I appreciate the "dumb 
> question" thread from earlier this weekend, since I do not completely 
> grasp the notion of objects myself.  I have done a brief tutorial in 
> PHP's classes from a book, but haven't seen a situation where it would 
> be helpful to me so far.  (Though this could easily be due to my 
> inexperience in programming.)
> 
> One of the reasons Python is recommended so heavily is that it is "true 
> object oriented".  And in response to 14-yr old Jimmy's request for 
> programming assistance, another python-tutor-lister recommended becoming 
> familiar with the use of objects.  Is the use of objects somehow more 
> tightly integrated into Python than in other languages such as PHP and 
> Perl?  I had assumed that I could learn Python's syntax and hopefully 
> get started with some small-scale development as a learning exercise, 
> and worry about objects later.  But is it a better idea to try to tackle 
> this topic as early on as possible?

Well, regarding the comparision to Perl and PHP, I think many consider
the use of objects to be more natural in Python.  In fact, everything
is an object in Python.  Don't let this scare you, though.  To answer
your real question, I don't think you have to consider object
orientation in the beginning.  One of the beauties of Python, in my
opinion, is that it supports many ways of programming (usually called
paradigms).

To begin programming in Python, learn the basic datatypes and start
playing with loops, functions and such.  And then, when you feel
curious about classes and other object oriented stuff, you go on tho
that part of the language.  It's all about wanting to learn
something.  When you're interested, there's no way to stop you from
learning. :)

Peace,
  Kalle
-- 
Kalle Svensson (kalle@gnupung.net) - Laziness, impatience, hubris: Pick two!
English: http://www.gnupung.net/  Svenska: http://www.lysator.liu.se/~kalle/
Stuff: ["http://www.%s.org/" % x for x in "gnu debian python emacs".split()]