|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
||||
|
||||
|
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
|
||||
|
||||
|
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. |
|
#3
|
||||
|
||||
|
Quote:
As always...it does! Thanks! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > file.seek in append mode |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|