Separate Rows in reader

Jiewei Huang jiewei24 at gmail.com
Wed Mar 27 23:26:22 CET 2013


On Wednesday, March 27, 2013 9:18:28 PM UTC+10, rusi wrote:
> On Mar 27, 2:35 pm, Jiewei Huang <jiewe... at gmail.com> wrote:
> 
> > On Tuesday, March 26, 2013 1:48:10 PM UTC+10, MRAB wrote:
> 
> > > On 26/03/2013 03:33, Jiewei Huang wrote:
> 
> >
> 
> > > > On Tuesday, March 26, 2013 11:40:51 AM UTC+10, Dave Angel wrote:
> 
> >
> 
> > > >> On 03/25/2013 09:05 PM, Jiewei Huang wrote:
> 
> >
> 
> > > >>> On Monday, March 25, 2013 11:51:51 PM UTC+10, rusi wrote:
> 
> >
> 
> > > >> If you insist on using GoogleGroups, then make sure you keep your quotes
> 
> >
> 
> > > >> small.  I'm about to stop reading messages that are double-spaced by
> 
> >
> 
> > > >> buggy software.
> 
> >
> 
> > > >> >>> <SNIP>
> 
> >
> 
> > > >> >> Have you tried the split (and perhaps strip) methods from
> 
> >
> 
> > > >> >>http://docs.python.org/2/library/stdtypes.html#string-methods
> 
> >
> 
> > > >> >> ?
> 
> >
> 
> > > >> You got lots of specific advice from your previous thread.  So which
> 
> >
> 
> > > >> version did you end up using?  It'd make a good starting place for this
> 
> >
> 
> > > >> "problem."
> 
> >
> 
> > > >> > can show me one line of how to implement it base on my problem?
> 
> >
> 
> > > >> As long as the input data is constrained not to have any embedded
> 
> >
> 
> > > >> commas, just use:
> 
> >
> 
> > > >>      mylist = line.split(",")
> 
> >
> 
> > > >> instead of print, send your output to a list.  Then for each line in the
> 
> >
> 
> > > >> list, fix the bracket problem to your strange specs.
> 
> >
> 
> > > >>      outline = outline.replace("[", "(")
> 
> >
> 
> > > > Hi Dave thanks for the tips,
> 
> >
> 
> > > > I manage to code this:
> 
> >
> 
> > > > f = open('Book1.csv', 'rU')
> 
> >
> 
> > > > for row in f:
> 
> >
> 
> > > >      print zip([row for (row) in f])
> 
> >
> 
> > > > however my output is
> 
> >
> 
> > > > [('John Konon Ministry of Moon Walks 4567882 27-Feb\n',), ('Stacy Kisha Ministry of Man Power 1234567 17-Jan\n',)]
> 
> >
> 
> > > > is there any method to remove the \n ?
> 
> >
> 
> > > Use the .rstrip method:
> 
> >
> 
> > >      print zip(row.rstrip('\n') for row in f)
> 
> >
> 
> > Hi the output is:
> 
> >
> 
> > [('John Cleese,Ministry of Silly Walks,5555421,27-Oct',), ('Stacy Kisha,Ministry of Man Power,1234567,17-Jan',)]
> 
> >
> 
> > how to make it to
> 
> >
> 
> > [CODE][('John Cleese', 'Ministry of Silly Walks' , '5555421', '27-Oct'), ('Stacy Kisha', 'Ministry of Man Power', '1234567,17-Jan')][/CODE]
> 
> >
> 
> > i need ' ' in all the row and the , to be remove after the date
> 
> 
> 
> Everything you need for this has been answered by Tim, Dave, myself
> 
> (and others?).
> 
> If you are stuck, tell us where.
> 
> If something did not work, tell us what.
> 
> 
> 
> Dont you think if you are asking us to do your homework, you should
> 
> offer us a little fee?
Hi Rusi, 

I'm truly struck and I did mention what did not work and i did follow the link you gave and i did come out with my own code which come out as a same result ( look at the #) however it is not the one i need.

f = open('friends.csv', 'rU') 
for row in f: 
    #print zip([row.rstrip() for (row) in f]) 
    print zip(row.rstrip('\n') for (row) in f)



More information about the Python-list mailing list