Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 20th, 2004, 11:36 AM
Boceifus's Avatar
Boceifus Boceifus is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 103 Boceifus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 1 h 17 m 20 sec
Reputation Power: 10
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?!?!?

Reply With Quote
  #2  
Old February 20th, 2004, 01:57 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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


Reply With Quote
  #3  
Old February 20th, 2004, 03:49 PM
Boceifus's Avatar
Boceifus Boceifus is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 103 Boceifus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 1 h 17 m 20 sec
Reputation Power: 10
Quote:
Originally Posted by netytan
Hope this helps ,

Mark.


As always...it does!
Thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > file.seek in append mode

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap