Printer list value problem
Tim Chase
python.list at tim.thechases.com
Tue Jan 14 14:38:11 EST 2014
On 2014-01-14 11:24, Mike wrote:
> 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:
>
> [........]
> user1 at example.com;user1;lastName;Name
> user2 at example.com;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
More information about the Python-list
mailing list