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


Groups > comp.lang.python > #63930

Re: Printer list value problem

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'read.': 0.03; '[0]': 0.09; 'f.close()': 0.09; 'iterate': 0.09; 'cc:addr:python-list': 0.11; '"with"': 0.16; "'rb')": 0.16; '-tkc': 0.16; 'bit.': 0.16; 'csv': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'unpack': 0.16; 'wrote:': 0.18; "skip:' 30": 0.19; 'value.': 0.19; 'example': 0.22; 'mike': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'subject:problem': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'script': 0.25; 'header:In-Reply-To:1': 0.27; '(this': 0.29; '[2]': 0.30; 'subject:list': 0.30; 'easier': 0.31; "skip:' 10": 0.31; 'indentation': 0.31; 'open': 0.33; 'reader': 0.33; 'moment': 0.34; "i'd": 0.34; 'problem': 0.35; 'something': 0.35; 'but': 0.35; 'charset:us-ascii': 0.36; 'list': 0.37; 'previous': 0.38; 'you.': 0.62; 'name': 0.63; 'to:addr:gmail.com': 0.65; 'mail,': 0.68; 'received:50.22': 0.84
Date Tue, 14 Jan 2014 13:38:11 -0600
From Tim Chase <python.list@tim.thechases.com>
To Mike <miguelcoam@gmail.com>
Subject Re: Printer list value problem
In-Reply-To <6139406d-9ccc-41b2-8aa8-7f6fd2431366@googlegroups.com>
References <6139406d-9ccc-41b2-8aa8-7f6fd2431366@googlegroups.com>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Get-Message-Sender-Via boston.accountservergroup.com: authenticated_id: tim@thechases.com
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5471.1389728238.18130.python-list@python.org> (permalink)
Lines 43
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1389728238 news.xs4all.nl 2923 [2001:888:2000:d::a6]:36735
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:63930

Show key headers only | 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