#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    103
    Rep Power
    11

    file.seek in append mode


    greets

    i have some text that i update.the data consists of a few strings,printed to the file as one line.now when i write the file for the first time,i can use file.seek() to controll where on the line a string goes.but when i try to do it in append mode,it just writes the strings right next to each other on the line.i am trying to make the file a little easier on the eye when its viewed(the strings aligned vertically).i want something like
    Code:
    string1     string2222222       string3
    string1     string22222         string3
    string1     string2222222222    string3
    but this is what im getting
    Code:
    string1     string2     string3
    string1string2string3
    string1string2string3
    i tried some thing like
    p=file.tell()
    p=(p+20)
    file.seek(p)
    file.write

    but it doesnt work.can anyone show me a example of something similar to what i want to do?
    It is not important if the glass is half full or half empty.What is important,is who has been drinking from MY glass?!?!?
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    The best way to do this is by padding the string to be writen to the file apropriatly. For this i'd use the ljust() string method i.e.

    Code:
    >>> format = file('file.txt', 'a')
    >>> format.write('string 1'.ljust(20))
    >>> format.write('string 2'.ljust(20))
    >>> format.write('string 3\n')
    >>> format.write('string 4'.ljust(20))
    >>> format.write('string 5'.ljust(20))
    >>> format.write('string 6\n')
    >>> format.write('string 7'.ljust(20))
    >>> format.write('string 8'.ljust(20))
    >>> format.write('string 9\n')
    >>> format.close()
    >>>
    Hope this helps ,

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    103
    Rep Power
    11
    Originally Posted by netytan
    Hope this helps ,

    Mark.
    As always...it does!
    Thanks!
    It is not important if the glass is half full or half empty.What is important,is who has been drinking from MY glass?!?!?

IMN logo majestic logo threadwatch logo seochat tools logo