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


Groups > comp.lang.python > #87075

Re: Append a file

Return-Path <jsf80238@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.016
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'skip:u 30': 0.07; 'subject:file': 0.07; 'f.close()': 0.09; 'line:': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; '"w")': 0.16; 'easier.': 0.16; 'ought': 0.16; 'two.': 0.16; 'url:)': 0.16; 'wrote:': 0.18; 'module': 0.19; 'seems': 0.21; 'command': 0.22; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'lines': 0.31; 'requests': 0.31; 'file': 0.32; 'fri,': 0.33; 'received:google.com': 0.35; 'url:org': 0.36; 'two': 0.37; 'jason': 0.38; 'pm,': 0.38; 'skip:u 10': 0.60; 'kind': 0.63; 'url:user': 0.65; 'to:addr:gmail.com': 0.65; 'sample': 0.67; 'mar': 0.68; 'results': 0.69; '2015': 0.84; 'url:latest': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=+2ANeq5yrB8dCDKlE8PwhzCF3LpdUJGy9cpV/YWcfQM=; b=LUaoZbjM7aHtoalfWc2/mMmgXMUTbJF3EmnJ/AJCXYHXovK2WxUXSLmMoQk9EmbR/U HJxE5U3ygLvQeB4jNI3ntY7oYdk7enFDiwfrzin8p5dCO4gvLMoPaVyTAVstS0E2epFp 38nKuEq2lH+15G15VERrHMuTRUyanvMrrZ2VU21+4alL2jHwazeZe3M6hUYN80Kj6m2e mP+t9nb/aUazV5G3FShBPqWrtipMYC1lCRuA6MGGt6nZlkJsgyJALteku0DEmvDrEjC2 uMrJm8fXPCHzJfCLgUmPK9QoEwYrVNBtxcd102zUobGUkkURNIi8SXlB0Dz3zffSg75d CESw==
MIME-Version 1.0
X-Received by 10.194.109.9 with SMTP id ho9mr35639469wjb.29.1425706638410; Fri, 06 Mar 2015 21:37:18 -0800 (PST)
In-Reply-To <adcd6103-cba5-4eda-9af6-e6ba95789159@googlegroups.com>
References <adcd6103-cba5-4eda-9af6-e6ba95789159@googlegroups.com>
Date Fri, 6 Mar 2015 22:37:18 -0700
Subject Re: Append a file
From Jason Friedman <jsf80238@gmail.com>
To Jason Venneri <jv92109@gmail.com>
Cc python-list <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.19
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.131.1425706640.21433.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1425706640 news.xs4all.nl 2900 [2001:888:2000:d::a6]:48851
X-Complaints-To abuse@xs4all.nl
Path csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Xref csiph.com comp.lang.python:87075

Show key headers only | View raw


On Fri, Mar 6, 2015 at 2:55 PM, Jason Venneri <jv92109@gmail.com> wrote:
> Hello, I'm using the urllib.urlretrieve command to retrieve a couple of lines of data.  I want to combine the two results into one file not two.
>
> Any suggestions?
>
> Sample
> urllib.urlretrieve('http://www.airplanes.com/data/boeing1.html','B747A.txt')
> urllib.urlretrieve('http://www.airplanes.com/data/boeing2.html','B747B.txt')
>
> I would like one file say B747C that contains the data from B747A and B747B in a file named B747C

>>> f = open("B747C.txt", "w")
>>> look_for = "Aircraft,"
>>> for line in open("B747A.txt"):
...     if look_for in line:
...         f.write(line)
...
>>> for line in open("B747B.txt"):
...     if look_for in line:
...         f.write(line)
...
>>> f.close()

Seems like you are using Python 2, you ought to consider Python 3.

The requests module
(http://docs.python-requests.org/en/latest/user/install/) makes this
kind of work easier.

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


Thread

Append a file Jason Venneri <jv92109@gmail.com> - 2015-03-06 13:55 -0800
  Re: Append a file sohcahtoa82@gmail.com - 2015-03-06 14:05 -0800
  Re: Append a file Jason Friedman <jsf80238@gmail.com> - 2015-03-06 22:37 -0700
  Re: Append a file Jason Venneri <jven2eri@gmail.com> - 2015-03-08 22:11 -0700

csiph-web