[Tutor] help (fwd)

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Tue, 2 Oct 2001 00:05:00 -0700 (PDT)


Dear Riddle Box,

I have to apologize in advance; I haven't had time to answer your question
yet.  To make sure it actually gets answered, let me forward it to the
rest of Python's Tutor list.  When talking to people on tutor, try to keep
the messages on-list, so that others can learn and comment.

(I actually have something of a presentation that's due on Thursday, so
I'm somewhat out of commission for the moment.)

Best of wishes to you!


 ---------- Forwarded message ----------
Date: Mon, 1 Oct 2001 17:54:00 -0700
From: RIDDLE BOX <riddlebox@vitalogy.org>
To: dyoo@hkn.eecs.berkeley.edu
Subject: RE: Re: [Tutor] help

Hello,

I may have the been trying to do this wrong with that code, but I would
like the program to look at a file and then when you are done looking at
that file, I would like it to ask if you would like to look at another
file, and keep asking that until you quit the program. this is my whole
code right now. I hope I am on the right track.  thanks for all your help
:)


    class App:
        def __init__(self, master):

            frame = Frame(master)
            frame.pack()

            self.button = Button(frame, text="quit", fg="blue", command=frame.quit)
            self.button.pack(side=RIGHT)

            self.second_chance = Button(frame, text="would you like to look at another file?", fg="red", command=self.second_chance)
            self.second_chance.pack(side=LEFT)

        def second_chance(self):
            read = raw_input("where is the file located?")
            inp = open(read, "r")
            for line in inp.readlines():
                print line



root = Tk()

app = App(root)





>Date: Mon, 1 Oct 2001 14:01:46 -0700 (PDT)
> Danny Yoo <dyoo@hkn.eecs.berkeley.edu> RIDDLE BOX <riddlebox@vitalogy.org>cc: tutor@python.org
> Re: [Tutor] help
>On Mon, 1 Oct 2001, RIDDLE BOX wrote:
>
>> I am having trouble trying to get a loop into my program, and I am
>> wondering if someone could help me better understand using "while"?
>> 
>> here is a copy of the code that I am having trouble with if someone
>> could explain what I am doing wrong I would appreciate it thanks
>> 
>>     def second_chance(self):
>>             j = second
>>             while j = open:
>>             read = raw_input("where is the file located?")
>>             inp = open(read, "r")
>>             for line in inp.readlines():
>>                 print line
>
>The "while" loop is sorta similar to the "for" loop in that it allows us
>to repeat things over and over.
>
>
>While the "for" loop iterates over a sequence of things, "while" does
>something while a condition is true.
>
>For example:
>
>###
>while 1:
>   print "I am an infinite loop."
>###
>
>will run in an infinite loop because "1" is considered to be a true value
>in Python.
>
>
>Here's another example:
>
>###
>print "Counting down"
>x = 10
>while x >= 0:
>    print x
>    x = x - 1
>###
>
>
>
>Let's take a look at your program snippet again:
>
>>     def second_chance(self):
>>             j = second
>>             while j = open:
>>             read = raw_input("where is the file located?")
>>             inp = open(read, "r")
>>             for line in inp.readlines():
>>                 print line
>
>There's some small syntax that can be easily corrected: the body of the
>while loop needs to be indented.
>
>However, I have to admit that I'm a little confused about how the program
>plans to use the while loop.  Can you explain a little more about what you
>want to do?  Maybe then we can see if the while loop is a good thing to
>use for this method.
>
>
>Best of wishes to you.




------------------------------------------------------------
This Email Is Provided Free Of Charge Thanks To http://www.vitalogy.org
Sponsored by: http://www.iminteractive.net Internet Solutions, web host & more!