Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41863
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-03-26 00:24 -0700 |
| References | (3 earlier) <f085bd7b-2bb3-46be-88b5-292e5f181a95@kw7g2000pbb.googlegroups.com> <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> <mailman.3710.1364262083.2939.python-list@python.org> <df59e5f7-8e00-4048-8878-a62e08960524@googlegroups.com> <mailman.3713.1364269874.2939.python-list@python.org> |
| Subject | Re: Separate Rows in reader |
| From | Jiewei Huang <jiewei24@gmail.com> |
| Message-ID | <mailman.3724.1364283327.2939.python-list@python.org> (permalink) |
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)
thanks ! got it working!
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-23 22:20 -0700
Re: Separate Rows in reader Dave Angel <davea@davea.name> - 2013-03-24 01:46 -0400
Re: Separate Rows in reader rusi <rustompmody@gmail.com> - 2013-03-24 00:34 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-24 01:18 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-24 01:11 -0700
Re: Separate Rows in reader Dave Angel <davea@davea.name> - 2013-03-24 09:03 -0400
Re: Separate Rows in reader Tim Chase <python.list@tim.thechases.com> - 2013-03-24 08:49 -0500
Re: Separate Rows in reader rusi <rustompmody@gmail.com> - 2013-03-24 08:57 -0700
Re: Separate Rows in reader Tim Chase <python.list@tim.thechases.com> - 2013-03-24 13:28 -0500
Re: Separate Rows in reader rusi <rustompmody@gmail.com> - 2013-03-24 19:08 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-24 01:11 -0700
Re: Separate Rows in reader ypsun <winter0128@gmail.com> - 2013-03-24 03:58 -0700
Re: Separate Rows in reader ypsun <winter0128@gmail.com> - 2013-03-24 04:10 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-24 23:52 -0700
Re: Separate Rows in reader rusi <rustompmody@gmail.com> - 2013-03-25 06:51 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-25 18:05 -0700
Re: Separate Rows in reader Dave Angel <davea@davea.name> - 2013-03-25 21:40 -0400
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-25 20:33 -0700
Re: Separate Rows in reader MRAB <python@mrabarnett.plus.com> - 2013-03-26 03:48 +0000
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-26 00:24 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-26 00:24 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-27 02:35 -0700
Re: Separate Rows in reader rusi <rustompmody@gmail.com> - 2013-03-27 04:18 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-27 15:12 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-27 15:26 -0700
Re: Separate Rows in reader rusi <rustompmody@gmail.com> - 2013-03-27 18:24 -0700
Re: Separate Rows in reader Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-28 01:32 +0000
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-27 02:35 -0700
Re: Separate Rows in reader Tim Roberts <timr@probo.com> - 2013-03-28 21:28 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-25 20:33 -0700
Re: Separate Rows in reader Jiewei Huang <jiewei24@gmail.com> - 2013-03-24 18:15 -0700
csiph-web