Printer list value problem

M

Mike

Hello,
I confudsed,need printer the value of list (this is reaer from csv) . The reader is ok, but my problem is in the print moment because printer only the last value. For example my csv is:

[........]
(e-mail address removed);user1;lastName;Name
(e-mail address removed);user2;lastName;Name
[........]

But when execute the script I view the print is only the last user

[........]
ca (e-mail address removed) displayName 'user2' sn 'lastName' cn 'Name'
[........]

And I need the next printer

[........]
ca (e-mail address removed) displayName 'User1' sn ''lastName" cn 'Name'
ca (e-mail address removed) displayName 'User2' sn ''lastName" cn 'Name'
[........]

My script is

[........]
#!/usr/bin/python
import csv
with open ('users.csv', 'rb') as f:

reader = csv.reader (f, delimiter=';' ) #delimiter tabulador
for row in reader:

mail = row [0]
name = row [3]
lastname = row [2]

print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname)

f.close()
[........]


Thanks.
 
M

MRAB

Hello,
I confudsed,need printer the value of list (this is reaer from csv) . The reader is ok, but my problem is in the print moment because printer only the last value. For example my csv is:

[........]
(e-mail address removed);user1;lastName;Name
(e-mail address removed);user2;lastName;Name
[........]

But when execute the script I view the print is only the last user

[........]
ca (e-mail address removed) displayName 'user2' sn 'lastName' cn 'Name'
[........]

And I need the next printer

[........]
ca (e-mail address removed) displayName 'User1' sn ''lastName" cn 'Name'
ca (e-mail address removed) displayName 'User2' sn ''lastName" cn 'Name'
[........]

My script is

[........]
#!/usr/bin/python
import csv
with open ('users.csv', 'rb') as f:

reader = csv.reader (f, delimiter=';' ) #delimiter tabulador
for row in reader:

mail = row [0]
name = row [3]
lastname = row [2]

This line is indented the same amount as the 'for' loop, which means
that it will be executed after the loop has finished.
print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname)
You don't need to close the file here because the 'with' statement will
do that for you.
f.close()
[........]


Thanks.
 
T

Tim Chase

Hello,
I confudsed,need printer the value of list (this is reaer from
csv) . The reader is ok, but my problem is in the print moment
because printer only the last value. For example my csv is:

[........]
(e-mail address removed);user1;lastName;Name
(e-mail address removed);user2;lastName;Name
[........]

But when execute the script I view the print is only the last user
with open ('users.csv', 'rb') as f:

reader = csv.reader (f, delimiter=';' ) #delimiter tabulador
for row in reader:

mail = row [0]
name = row [3]
lastname = row [2]

print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname)

This print needs to be at the same indentation as the previous bit.

f.close()

This .close() is superfluous--the "with" takes care of that for you.

I'd also unpack the row as I iterate to make it easier to read. That
would make the final look something like

with open("users.csv", "rb") as f:
reader = csv.reader(f, delimiter=';')
for mail, _, lastname, name in reader:
print "ca {} displayName '{}' sn '{}'".format(
mail, name, lastname)

-tkc
 
M

Mike

El martes, 14 de enero de 2014 16:32:49 UTC-3, MRAB escribió:
I confudsed,need printer the value of list (this is reaer from csv) . The reader is ok, but my problem is in the print moment because printer onlythe last value. For example my csv is:
[........]
(e-mail address removed);user1;lastName;Name
(e-mail address removed);user2;lastName;Name
[........]

But when execute the script I view the print is only the last user
[........]

ca (e-mail address removed) displayName 'user2' sn 'lastName' cn 'Name'
[........]

And I need the next printer
[........]

ca (e-mail address removed) displayName 'User1' sn ''lastName" cn 'Name'
ca (e-mail address removed) displayName 'User2' sn ''lastName" cn 'Name'
[........]

My script is
[........]
#!/usr/bin/python

import csv
with open ('users.csv', 'rb') as f:

reader = csv.reader (f, delimiter=';' ) #delimiter tabulador
for row in reader:
mail = row [0]
name = row [3]
lastname = row [2]



This line is indented the same amount as the 'for' loop, which means

that it will be executed after the loop has finished.


print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname)

You don't need to close the file here because the 'with' statement will

do that for you.



Hello MRAB,
I remove the "f.close" and after execute the script but still i have the same result (print the last row)

Thanks
 
M

Mark Lawrence

El martes, 14 de enero de 2014 16:32:49 UTC-3, MRAB escribió:
I confudsed,need printer the value of list (this is reaer from csv) . The reader is ok, but my problem is in the print moment because printer only the last value. For example my csv is:
[........]
(e-mail address removed);user1;lastName;Name
(e-mail address removed);user2;lastName;Name
[........]

But when execute the script I view the print is only the last user
[........]

ca (e-mail address removed) displayName 'user2' sn 'lastName' cn 'Name'
[........]

And I need the next printer
[........]

ca (e-mail address removed) displayName 'User1' sn ''lastName" cn 'Name'
ca (e-mail address removed) displayName 'User2' sn ''lastName" cn 'Name'
[........]

My script is
[........]
#!/usr/bin/python

import csv
with open ('users.csv', 'rb') as f:

reader = csv.reader (f, delimiter=';' ) #delimiter tabulador
for row in reader:
mail = row [0]
name = row [3]
lastname = row [2]



This line is indented the same amount as the 'for' loop, which means

that it will be executed after the loop has finished.


print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname)

You don't need to close the file here because the 'with' statement will

do that for you.



Hello MRAB,
I remove the "f.close" and after execute the script but still i have the same result (print the last row)

Thanks

Your print statement needs to be inside the for loop, you currently have
it after the loop has finished.

Would you also please read and action this
https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the
double line spacing above, thanks.
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top