#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    2
    Rep Power
    0

    Formatted writing to a file


    I am trying to write to a file multiple times before close. Using the following sequence:

    outfile = open(data_file, 'w' )
    x=5
    while x > 0
    x = x - 1
    datax is read from a file.

    outfile.write('%25s' %datax + "|\n")

    This loop will write 5 lines at column position 25. I later come back to the same code and want to write 5 more lines at column 50 starting on line 1 and not line 6.

    My questions are:

    1. how can I format outfile so i can write multiple lines and then apend multiple lines later before closing the file?

    2. how can I make data formatting string '%25s' intiger (in this case 25) a variable?

    Thanks in advance.

    boomeral@hotmail.com
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    open(data_file, 'w');
    Code:
    x = 5;
    while(x > 0):
        x -= 1;
    open(data_file, 'a').write('%25s' %datax + "|\n");
    Im a bit confused on what you want '%25s' %datax + "|\n" to do.

IMN logo majestic logo threadwatch logo seochat tools logo