hi All,
I am importing the SQL DB data into a CSV file, the length of the data is too large and doesn't fit with default csv file column width, so i need to increase the column width please let me know how can you achieve this .

below is my code
import csv
cursor.execute ("select * from watch where timestamp>='2011-05-30' and env='qa'")
row = cursor.fetchone ()
f=csv.writer(open(os.getcwd()+"\\analytics.csv",'w'))
f.writerow(row)

Recommended Answers

All 9 Replies

csv does not have default column width I think, but mayby csv.writer does. If it does in the dialect you use, you can adjust it with

csv.field_size_limit([new_limit]) 
Returns the current maximum field size allowed by the parser. If new_limit is given, this becomes the new limit.
>>> import csv
>>> csv.field_size_limit()
131072

how to set different column width for different columns.
please provide sample code

I import multiple column values from db and i need write this into csv file, based the column data size please let me know how to achieve this

csv does not have columns. Give sample input and derived output

i import the data from database and save into .csv file this file looks similar excel sheet, where my comma separated data sits into each column of this csv sheet and each column has different length of data so i need to fit this data into csv file

And what kind of error you are getting?

i do not get any errors wen i run the below code
import csv
cursor.execute ("select * from watch where timestamp>='2011-05-30' and env='qa'")
row = cursor.fetchone ()
f=csv.writer(open(os.getcwd()+"\\analytics.csv",'w'))
f.writerow(row)

data from databasae is imported into csv file. since the lenght of the data is more means the length of the characters that sits into these csv file columns is more i ned to increase the coulmn width of the csv file.
i need to increase the columns for multiple columns based on the lenght of the data.
so i want to know how to achive this

can some one suggest me as how to achieve this

We (or I, anyway) still don't really understand what it is you're trying to achieve. If you could include a small sample .csv file that you generate using your code, and then show us what you think it should look like instead, rather than speaking in abstractions, maybe that would help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.