#1
  1. No Profile Picture
    inexperienced and useless
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    Stevenage, uk
    Posts
    10
    Rep Power
    0

    writing a list to a file


    How do I write a list to a file, becuase I seem to not be able to do it?
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2002
    Location
    Atlanta, Ga
    Posts
    1
    Rep Power
    0

    Lightbulb


    NOTE: Be sure that the data in the list are strings, or make sure that you are writing strings to the file at least.

    Here's an example:
    ============================

    # Create a file object and open file
    # create an empty list
    # populate the list with numbers ranging 1..10
    # convert number in list to strings
    # write the list to a file
    # close the file

    #!/usr/bin/env python

    myfile = open('myfile', 'w')
    mylist = []
    for x in range(1,11): mylist.append(x)
    mylist = map(lambda(x): str(x), mylist)
    myfile.writelines(mylist)
    myfile.close()

    =================================

IMN logo majestic logo threadwatch logo seochat tools logo