Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #63930

Re: Printer list value problem

Date 2014-01-14 13:38 -0600
From Tim Chase <python.list@tim.thechases.com>
Subject Re: Printer list value problem
References <6139406d-9ccc-41b2-8aa8-7f6fd2431366@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.5471.1389728238.18130.python-list@python.org> (permalink)

Show all headers | View raw


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@example.com;user1;lastName;Name
> user2@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


Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Printer list value problem Mike <miguelcoam@gmail.com> - 2014-01-14 11:24 -0800
  Re: Printer list value problem MRAB <python@mrabarnett.plus.com> - 2014-01-14 19:32 +0000
    Re: Printer list value problem Mike <miguelcoam@gmail.com> - 2014-01-14 11:54 -0800
      Re: Printer list value problem Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-14 20:03 +0000
  Re: Printer list value problem Tim Chase <python.list@tim.thechases.com> - 2014-01-14 13:38 -0600

csiph-web