Separate Rows in reader

Jiewei Huang jiewei24 at gmail.com
Sun Mar 24 04:18:39 EDT 2013


On Sunday, March 24, 2013 5:34:03 PM UTC+10, rusi wrote:
> On Mar 24, 10:46 am, Dave Angel <da... at davea.name> wrote:
> 
> > On 03/24/2013 01:20 AM, Jiewei Huang wrote:
> 
> >
> 
> >
> 
> >
> 
> >this is the data in csv file http://imgur.com/L4qUkGQ
and this is the correct output that i need to get:
[('John Konon', 'Ministry of moon Walks', '4567882', '27-Feb'), 
( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] 
sorry for the confusion 

> 
> >
> 
> >
> 
> >
> 
> >
> 
> >
> 
> > > Hi all,
> 
> >
> 
> > > Currently create a simple text-based database of information about people
> 
> >
> 
> > > I have a csv file which consist of 3 rows , row 1 2 and 3 is as such:
> 
> > > Name        Address        Telephone       Birthday
> 
> > > John Konon Ministry of Moon Walks  4567882 27-Feb
> 
> > > Stacy Kisha        Ministry of Man Power   1234567 17-Jan
> 
> >
> 
> > > My codes are :
> 
> > > import csv
> 
> > > original = file('friends.csv', 'rU')
> 
> > > reader = csv.reader(original)
> 
> >
> 
> > > for row in reader:
> 
> >
> 
> > >      print row
> 
> >
> 
> > > and the output is :
> 
> > > ['Name', ' Address', 'Telephone', 'Birthday']
> 
> > > ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb']
> 
> > > ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan']
> 
> >
> 
> > > But i wanted to make it
> 
> >
> 
> > > [('John Cleese', 'Ministry of Silly Walks', '5555421', '27-Feb'),
> 
> > > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')]
> 
> >
> 
> > > can someone show me guidance to this issue
> 
> >
> 
> > > Thanks all
> 
> >
> 
> > There are at least 3 differences to the printouts.  Which difference are
> 
> > you concerned with?
> 
> >
> 
> > 1) Moon --> Silly
> 
> > 2) square and round brackets in slightly different places
> 
> > 3) row 0 suppressed
> 
> >
> 
> > Explain which one, or specify a fourth, and also what you have tried to
> 
> > address the question.
> 
> >
> 
> > --
> 
> > DaveA
> 
> 
> 
> Besides does it work as you are describing?
> 
> ie your input appears to be tab delimited, whereas the default is ','



More information about the Python-list mailing list