473,322 Members | 1,409 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,322 software developers and data experts.

Writing into a csv file

I am trying to write some data into a csv file, but when I write the file the data skips a line. I tried putting commas at the end of the write line but that did not work.

Attached is the part of the code where I write the data.

Expand|Select|Wrap|Line Numbers
  1. writer.writerow(datim + [button1]+ [row['cruise']] + [row['crunum']]+ [sitecode]+ [SeriesCode]+ [deploynum]+ [DeploymentCode]+ [ctd]+ [blat] + [blon]+[deploymenteklog]+ [Deploymentcom1 + str(deploynum)]),
  2.  
  3. writer.writerow(datim + [button2]+ [row['cruise']] + [row['crunum']]+[sitecode]+[SeriesCode]+[deploynum]+[DeploymentCode]+[ctd]+[elat]+[elon]+[deploymenteklog]+[Deploymentcom2 + str(deploynum)]),
  4.  
Thanks
Aug 5 '10 #1
3 1946
bvdet
2,851 Expert Mod 2GB
There's not much to go on, because I have no idea what the variables are assigned to. My guess is that one of the values has a trailing newline character. The newline character can be removed with str method strip().
Aug 6 '10 #2
Haiyan
17
Since you are using the csv module and the default line termination sequence is '\r\n', that's why you get a new line. You can try following way and it should work for you.
Expand|Select|Wrap|Line Numbers
  1. writer.writerow(yourrow, lineterminator = '\r')
Aug 6 '10 #3
dwblas
626 Expert 512MB
You can also use strip(), and avoid the possibility that some lines contain a newline and some do not.
Expand|Select|Wrap|Line Numbers
  1. str_out = ""
  2. for field in [datim, button1, row['cruise'], row['crunum'], sitecode, SeriesCode, deploynum, DeploymentCode, ctd, blat, blon, deploymenteklog, Deploymentcom1,  str(deploynum)]:
  3.     str_out += field.strip() 
And then write str_out configured however you wish.
Aug 11 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: JC | last post by:
I am using Mysql version: 4.0.18-max-log and trying to populate a database from a text file using source option from inside the mysql environment. The population run OK but when creating the...
2
by: CJ | last post by:
I've got following: > file_a content needs to be compared with file_b content. I want to write content in binary form, then run a line by line comparison on characters. When the first different...
0
by: sunphan | last post by:
Hello all I wanted to create a data file from a stored procedure in DB2. I have to select few millions records, do certain checking or calculation on fields, store/append it in file and this will...
1
by: brabster | last post by:
Hi, this is my first post so please excuse any mistakes! I'd like to write files using an upload script in my website, but I'm having problems. I don't seem to be able to write a file. Ive set up...
1
by: pablo.erba | last post by:
Hi Everyone, I´m new to this group, I´m trying to write a text files adding content from a text column (more than 8000 characters), I found code how to write files and it works but i have the...
6
by: William Manley | last post by:
According to what I read in the ConfigParser module, this should work, but it doesn't. Can anyone point out what I'm doing wrong? def writeinifile ( self, FILE='P:/INI/test.ini',...
1
by: Debabrata Jana | last post by:
Hi all, I use solaris 5.8 OS. I have three OS user : 1) orac9ias 2)oracle9i 3)backup I use the following command to export a oracle export backup (I use oracle9i release 1):
4
by: FingerDemon | last post by:
I'm guessing I'm missing something obvious here, but I have searched around and re-read my Python books and references on simple file writing and I can't see the answer. I am running this in Windows...
1
by: Mr fahad | last post by:
#include <stdio.h> #include <conio.h> void main (void) { char ch; FILE *fp; fp=fopen ("fahd.txt","w"); while (ch=fgetc( )!='\r') fputc (ch,fp); fclose (fp);
4
by: Jim | last post by:
Hi There, I'm trying to read a file character by character. When I write the file out, there is one extra character which shows on the screen as a solid circle with a small question mark in the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.