[Tutor] What's the invalid syntax? Code supplied

Nathan Pinno falcon3166 at hotmail.com
Thu Aug 4 03:51:43 CEST 2005


That's part of my signature. It describes who I am.
  ----- Original Message ----- 
  From: Bob Gailer 
  To: Nathan Pinno ; Tutor mailing list 
  Sent: Wednesday, August 03, 2005 7:48 PM
  Subject: Re: [Tutor] What's the invalid syntax? Code supplied


  At 06:21 PM 8/3/2005, Nathan Pinno wrote:

    Hey all,
     
    What wrong with the following syntax?
     
    def save_file(sitelist,filename):
        out_file = open(filename,"w")
        for site in sitelist.keys():
            out_file.write(site+","+sitelist[site][0]+","+sitelist[site][1]"\n")

  sitelist[site][1]"\n" is not valid. I think you want sitelist[site][1] + "\n"


        out_file.close()

  You can simplify things by using items():
   for key, value in sitelist.items():
       out_file.write(key +","+value[0] +","+value[1]+"\n")

  % formatting can make it even nicer:
       out_file.write("%s,%s,%s\n" % (key, value[0], value[1])


    It highlighted the last " if that will help any.
     
    I can't show you the error due to the fact that the error appeared in a separate box, instead of in the IDLE window.
     
    If you need the rest of the code, just ask. It ran perfect before I added file I/O.
     
    Thanks in advance,
    Nathan Pinno
    Crew, Camrose McDonalds and owner/operator of Woffee

  Just out of curiosity, would you explain "Crew, Camrose McDonalds and owner/operator of Woffee"

  Bob Gailer
  phone 510 978 4454 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050803/6fa93d2a/attachment-0001.htm


More information about the Tutor mailing list