Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90274
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <vincent@vincentdavis.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'none:': 0.07; 'subject:getting': 0.07; 'try:': 0.09; 'valueerror:': 0.09; 'wrong,': 0.09; 'received:209.85.218': 0.14; "'r',": 0.16; "'w')": 0.16; '(below)': 0.16; 'last)': 0.16; 'valueerror': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'skip:f 30': 0.19; 'seems': 0.21; 'to:name :python-list@python.org': 0.22; 'this?': 0.23; 'error': 0.23; 'file.': 0.24; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'file': 0.32; '(most': 0.33; 'reader': 0.33; 'skip:& 30': 0.33; 'skip:d 20': 0.34; 'subject:from': 0.34; 'received:209.85': 0.35; 'except': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'thanks': 0.36; 'should': 0.36; 'received:209': 0.37; 'skip:& 10': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'recent': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; '8bit%:6': 0.40; 'how': 0.40; 'new': 0.61; 'skip:n 10': 0.64; '8bit%:10': 0.64; '2015': 0.84; 'subject:before': 0.84 |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=ebywV+AiF+I9YKnnee5WSmAtVsvcEBpPkKQmeVpegFg=; b=PSz9kCUprEZQeks4Xnfz4LY/SxrrGvL9Ia3rZEV1iKtMSxZXswGKoRN8iRwYbC9M9Z 6UBgL6bFec7PdqIIc4CiY6xk5qd4WQNjniSrfjLg1khlDWb3VC42gGSDvkp/BQ4rDZ/t pBkBIoCKvKdwcDNdyKGzXc0e5AWsyOhgHMb6Y/1d3UNeileDL1mA4OvP8PG0Tuic0YYt aJ4+hWEEZM+uV2G28bhpKMJLNC91tdkDcgoqyzA4LebXMz2yNxy7lpeDiERAGwzWNzqp YdMfSBNim2xgNCjvhynWX4F4N1sMBo0lRuqTBdAdkv5KDOUbHuK4DzW2oTJoidnJiBmi GWqA== |
| X-Gm-Message-State | ALoCoQnPNDJi4ZMIN1qosTrngrcJzaCZoBzypsHzUuZ3nvAuUgcZaStTelpSR7eg19/C5L3ff/gD |
| X-Received | by 10.60.175.72 with SMTP id by8mr3256726oec.35.1431212515055; Sat, 09 May 2015 16:01:55 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <CALyJZZV8XFjbmiNRYxoAFuGHS2iix4knv-smn5adicVRAJ7ZCg@mail.gmail.com> |
| References | <CALyJZZV8XFjbmiNRYxoAFuGHS2iix4knv-smn5adicVRAJ7ZCg@mail.gmail.com> |
| From | Vincent Davis <vincent@vincentdavis.net> |
| Date | Sat, 9 May 2015 17:01:34 -0600 |
| Subject | Re: getting fieldnames from Dictreader before reading lines |
| To | "python-list@python.org" <python-list@python.org> |
| Content-Type | multipart/alternative; boundary=047d7bd7648e8eeefd0515ae21bb |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| 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.293.1431212523.12865.python-list@python.org> (permalink) |
| Lines | 138 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1431212523 news.xs4all.nl 2953 [2001:888:2000:d::a6]:58447 |
| X-Complaints-To | abuse@xs4all.nl |
| X-Received-Bytes | 10910 |
| X-Received-Body-CRC | 541164983 |
| Xref | csiph.com comp.lang.python:90274 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Not sure what I was doing wrong, it seems to work now. Vincent Davis 720-301-3003 On Sat, May 9, 2015 at 4:46 PM, Vincent Davis <vincent@vincentdavis.net> wrote: > I am reading a file with Dictreader and writing a new file. I want use the > fieldnames in the Dictwriter from the reader. See below How should I be > doing this? > > See how I am using reader.fieldnames in the the Dictwriter. I get an error > (below) > > with open(readfile, 'r', encoding='utf-8', errors='ignore', newline='') as > csvread: > reader = DictReader(csvread) > with open(writefile, 'w') as csvwrite: > writer = DictWriter(csvwrite, delimiter=',', > fieldnames=reader.fieldnames) > for line in reader: > pass > > ValueError Traceback (most recent call last)<ipython-input-13-0dac622bb8a9> in <module>()----> 1 reader.fieldnames() > /Users/vmd/anaconda/envs/py34/lib/python3.4/csv.py in fieldnames(self) 94 if self._fieldnames is None: 95 try:---> 96 self._fieldnames = next(self.reader) 97 except StopIteration: 98 pass > ValueError: I/O operation on closed file. > > > > Thanks > Vincent > Davis > >
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: getting fieldnames from Dictreader before reading lines Vincent Davis <vincent@vincentdavis.net> - 2015-05-09 17:01 -0600
csiph-web