Separate Rows in reader

M

MRAB

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)
 
J

Jiewei Huang

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!
 
J

Jiewei Huang

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!
 
J

Jiewei Huang

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')]

i need ' ' in all the row and the , to be remove after the date
 
J

Jiewei Huang

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')]

i need ' ' in all the row and the , to be remove after the date
 
R

rusi

On 26/03/2013 03:33, Jiewei Huang wrote:
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 forthis
"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')]

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?
 
J

Jiewei Huang

On 26/03/2013 03:33, Jiewei Huang wrote:
On 03/25/2013 09:05 PM, Jiewei Huang 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.
Have you tried the split (and perhaps strip) methods from
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
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')]
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 struck and i did say what did not work and i did follow your guideline and i
did come out with my own code which come out as a same result ( look at the#) not 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)
 
J

Jiewei Huang

On 26/03/2013 03:33, Jiewei Huang wrote:
On 03/25/2013 09:05 PM, Jiewei Huang 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.
Have you tried the split (and perhaps strip) methods from
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
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')]
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)
 
R

rusi

33, Jiewei Huang wrote:
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.  Sowhich
version did you end up using?  It'd make a good starting placefor 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',), ('StacyKisha 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')]
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 thelink you gave and i did come out with my own code which come out as a sameresult ( 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)
s=' John Cleese, Ministry of Silly Walks,5555421,27-Oct \n'
s.split(',') [' John Cleese', ' Ministry of Silly Walks', '5555421', '27-Oct \n']
s.strip().split(',') ['John Cleese', ' Ministry of Silly Walks', '5555421', '27-Oct']
 
S

Steven D'Aprano

Eight levels of attribution. And I count up to nine levels of quoting.

Doesn't anyone have a working backspace key in their editor? Please trim
your responses to what's needed to establish context, there's no need to
keep the entire thread duplicated in every post.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top