Return-Path: 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: References: Date: Fri, 6 Mar 2015 22:37:18 -0700 Subject: Re: Append a file From: Jason Friedman To: Jason Venneri Cc: python-list 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Fri, Mar 6, 2015 at 2:55 PM, Jason Venneri 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.