[Tutor] Filtering text files

David Talaga dtalaga at novodynamics.com
Wed Apr 14 20:22:06 EDT 2004


Filtering text filesCan I get some help here!! <just kidding> Ok, here's the
deal, I am using tkinter and trying to figure out how to un select the radio
button at startup.  here is my code in it's entirety.

import os
import Tkinter
root=Tkinter.Tk()
var=Tkinter.StringVar()
entry=Tkinter.Entry(root, textvariable=var)
entry.focus_set()
entry.pack()
var.set(root.title())
def changeTitle(): root.title(var.get())
def changeDriveC(): os.chdir('C:\\')
def changeDriveD(): os.chdir('D:\\')
def changeDriveE(): os.chdir('E:\\')
def changeDriveF(): os.chdir('F:\\')
def changeDriveG(): os.chdir('G:\\')
Tkinter.Button(root, text="Change Title", command=changeTitle).pack()
Tkinter.Button(root, text="Iconify", command=root.iconify).pack()
Tkinter.Button(root, text="Close", command=root.destroy).pack()
C=Tkinter.Radiobutton(text="Change dir to C:", value=0).pack()
D=Tkinter.Radiobutton(text="Change dir to D:", value=0).pack()
E=Tkinter.Radiobutton(text="Change dir to E:", value=0).pack()
F=Tkinter.Radiobutton(text="Change dir to F:", value=0).pack()
G=Tkinter.Radiobutton(text="Change dir to G:", value=0).pack()
if C.select():
    C=Tkinter.Radiobutton(text="Change dir to C:",
value=1,command=os.chdir('C:\\').pack()

Tkinter.mainloop


The if statement was a test that went wrong.  Anyone? Anyone?

Eric Idle is king!
David Talaga
  -----Original Message-----
  From: tutor-bounces at python.org [mailto:tutor-bounces at python.org]On Behalf
Of Kooser, Ara S
  Sent: Wednesday, April 14, 2004 5:28 PM
  To: 'tutor at python.org'
  Subject: [Tutor] Filtering text files


  Hello,

     I posted several question about filtering text files. I am still a
little confused. I ran through some of the tutorials on python.org and I am
still getting hung up. I am running python 2.3.3. When I try and run the
program below I receive the prompt on the shell and no new file is created
in my directory. Here is the code from
http://www.ibiblio.org/obp/thinkCSpy/chap11.htm. I have in my directory a
file named lmps for the input file. Also do the names in the function have
to be the same as the names of the files being loaded? I have tried both.
Thanks

  Ara

  def filterFile(lmps, newFile):
    f1 = open(lmps, "r")
    f2 = open(newFile, "w")
    while 1:
      text = f1.readline()
      if text == "":
        break
      if text[0] == 'I':
        continue
      f2.write(text)
    f1.close()
    f2.close()
    return
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040414/fcdfe8fe/attachment.html


More information about the Tutor mailing list