473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Writting to specific location in a file

I have a database result set in a Python list. Each row is a tuple.
data = [(a_field,b_field,c_field,d_field,x_field,y_field,z _field)]

I need to loop thru this data and write each row to a text file.

f = open('out.txt','w')
for row in data:
f.writelines(row)
My chanllenge is that each field needs to have a exact specific
position in the output file.
For instance a_field needs to start at position 2 in the line, b_fields
at position 18 and so on, for all the fields on each line.
What is a way of approaching this problem. I was think of maybe
creating a Cheetah template file. Is there a simple way to go?

Can anyone point me to a possible way of doing this?
Thanks a lot,

Arnaldo

Jul 18 '05 #1
1 2180
ar*****@gmail.com wrote:
My chanllenge is that each field needs to have a exact specific
position in the output file.
For instance a_field needs to start at position 2 in the line, b_fields
at position 18 and so on, for all the fields on each line.


You can use string formatting operations:

row = ("a", "b")
print " %-16s%-16s" % row

http://docs.python.org/lib/typesseq-strings.html
--
Michael Hoffman
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to...
1
by: Li Pang | last post by:
Hi, I receive daily an email with a attached file from my Outlook inbox. This file must be saved into a specific location manually. I made an app to automate this process. My app can read the...
2
by: Darrel | last post by:
My app has an 'admin' folder. This is the only directory i need to apply forms authentication to. Googling seems to indicate that the solution is to just give the admin folder it's own config...
0
by: noridotjabi | last post by:
As some of you may know I am working on a mini operating system. For it I need to write a filesystem that just apears to the current OS that is running my mini-OS as a large file. I think I have...
2
by: Craig | last post by:
I have the need to write a byte of information to a specific location in a text file. eg. the file looks something like this. FYYNN Line 1 Line 2 <eof>
3
by: Chicagoboy27 | last post by:
All I am trying to specify a location for the file to be saved in. currently I have a process that get the location of the file and then prompts the user to save it in a directory. I am wondering...
1
by: ramvenkat | last post by:
HI can we create specific folder through flash application inorder to save a external file for eg I have flash exe and i would like to save particular external file from the server to a local...
3
by: diwakar09 | last post by:
Hi, I have three classes, each one has distinct role apart from this there is main. from main the flows goes as follows main-->CTestForLog(create and run the thread) and in...
0
by: blackjackkiller | last post by:
Hi Need help in automating the report.Let me give the explanation what i need that might help u in understanding it. 1 need excel macro to run a query to pull data from sql server for specific...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.