[Tutor] Filtering text files

David Talaga dtalaga at novodynamics.com
Wed Apr 14 20:34:43 EDT 2004


Filtering text filesok, so I am an idiot! There wan no ) after the .pack( ).
Never mind about that. But now it is saying the this "AttributeError:
'NoneType' object has no attribute 'select'"
in the ugly red letters.  What now?!?!?!
  -----Original Message-----
  From: David Talaga [mailto:dtalaga at novodynamics.com]
  Sent: Wednesday, April 14, 2004 8:29 PM
  To: David Talaga; Kooser, Ara S; tutor at python.org
  Subject: RE: [Tutor] Filtering text files


  Oh yea, including this, the other problem I am having is when I run it the
statement after the if statements is aid to be illegal syntax!?!?!?!
  The revised code is as follows:
  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()
  elif D.select():
      D=Tkinter.Radiobutton(text="Change dir to D:",
value=1,command=os.chdir('D:\\').pack()
  elif E.select():
      E=Tkinter.Radiobutton(text="Change dir to D:",
value=1,command=os.chdir('E:\\').pack()
  elif F.select():
      F=Tkinter.Radiobutton(text="Change dir to D:",
value=1,command=os.chdir('F:\\').pack()
  elif G.select():
      G=Tkinter.Radiobutton(text="Change dir to D:",
value=1,command=os.chdir('G:\\').pack()

  Tkinter.mainloop

    -----Original Message-----
    From: tutor-bounces at python.org [mailto:tutor-bounces at python.org]On
Behalf Of David Talaga
    Sent: Wednesday, April 14, 2004 8:22 PM
    To: Kooser, Ara S; tutor at python.org
    Subject: RE: [Tutor] Filtering text files


    Can 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/4202f088/attachment-0001.html


More information about the Tutor mailing list