Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98982
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: How can I export data from a website and write the contents to a text file? |
| Date | Thu, 19 Nov 2015 03:57:58 +1100 |
| Lines | 13 |
| Message-ID | <mailman.418.1447865881.16136.python-list@python.org> (permalink) |
| References | <9365cf2f-e9c7-4338-83b4-ce3d1d7ce1d6@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de DeBZHU+/A4glBAX0Lkn2fwZ0Tzo12U+Q+lfB6qLnCKKw== |
| Return-Path | <rosuav@gmail.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; 'received:209.85.223': 0.03; 'subject:text': 0.04; 'skip:o 50': 0.07; 'subject:file': 0.07; 'cc:addr:python-list': 0.09; 'subject:How': 0.09; '"\\n")': 0.09; 'subject: \n ': 0.15; 'thu,': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'overwriting': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:export': 0.16; 'wrote:': 0.16; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'loop,': 0.29; 'once,': 0.29; 'subject:website': 0.29; 'statement': 0.32; 'instead,': 0.33; 'open': 0.33; 'file': 0.34; 'received:google.com': 0.35; 'nov': 0.35; 'received:209.85': 0.36; 'closing': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'subject:from': 0.39; 'subject:the': 0.39; 'close': 0.61; 'here.': 0.62; "'with'": 0.84; 'chrisa': 0.84; 'subject:write': 0.84; 'to:none': 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:cc :content-type; bh=eJo16jzWuct8Qx6rF4y6fh58kqaDpeNnS5xLj05WPL4=; b=ulNS2ytlupUAe+G3eiS0ohxmxeUJchuBADS4Sl7Z+Uu7PpLQrC/jOwgCkD/AHV2El4 7x1FrAaZyO33cmoDNoWg4BWad7CsPSHwZTUMl2KH+2kAuT+FjAjHunDeKe7DGHFzK+7O 83XQeCMM9CO4HVL80dGYcRM4ZVrgM/tr+OaDZQ31JDMu8/JP99jKTRf48JVnDCv4ttDH lMm8diGAMGGyEqSvO9oJ+aqBTJCjm8hkPIch5kDxe7OKBw7608kYFYaY5K4K/0b8iWVB 5Pv1qIurHrXXRHw4/H97gb4BWoBdCCc5x9bYRdFj/dQ2W1p5OuY/HGrssmMQqVtcYcR1 17vA== |
| X-Received | by 10.107.3.163 with SMTP id e35mr3580369ioi.157.1447865878840; Wed, 18 Nov 2015 08:57:58 -0800 (PST) |
| In-Reply-To | <9365cf2f-e9c7-4338-83b4-ce3d1d7ce1d6@googlegroups.com> |
| 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> |
| Xref | csiph.com comp.lang.python:98982 |
Show key headers only | View raw
On Thu, Nov 19, 2015 at 3:37 AM, ryguy7272 <ryanshuell@gmail.com> wrote:
> text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb")
> z = str(link)
> text_file.write(z + "\n")
> text_file.write("\n")
> text_file.close()
You're opening the file every time you go through the loop,
overwriting each time. Instead, open the file once, then start the
loop, and then close it at the end. You can use a 'with' statement to
do the closing for you, or you can do it the way you are here.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How can I export data from a website and write the contents to a text file? ryguy7272 <ryanshuell@gmail.com> - 2015-11-18 08:37 -0800
Re: How can I export data from a website and write the contents to a text file? Chris Angelico <rosuav@gmail.com> - 2015-11-19 03:57 +1100
Re: How can I export data from a website and write the contents to a text file? ryguy7272 <ryanshuell@gmail.com> - 2015-11-18 09:03 -0800
Re: How can I export data from a website and write the contents to a text file? ryguy7272 <ryanshuell@gmail.com> - 2015-11-18 09:15 -0800
Re: How can I export data from a website and write the contents to a text file? Denis McMahon <denismfmcmahon@gmail.com> - 2015-11-18 17:19 +0000
Re: How can I export data from a website and write the contents to a text file? ryguy7272 <ryanshuell@gmail.com> - 2015-11-18 09:40 -0800
Re: How can I export data from a website and write the contents to a text file? ryguy7272 <ryanshuell@gmail.com> - 2015-11-18 09:43 -0800
Re: How can I export data from a website and write the contents to a text file? Patrick Hess <patrickhess@gmx.net> - 2015-11-19 20:17 +0100
Re: How can I export data from a website and write the contents to a text file? Michael Torrie <torriem@gmail.com> - 2015-11-20 10:44 -0700
Re: How can I export data from a website and write the contents to a text file? Rob Gaddi <rgaddi@technologyhighland.invalid> - 2015-11-18 18:05 +0000
Re: How can I export data from a website and write the contents to a text file? Random832 <random832@fastmail.com> - 2015-11-18 16:38 -0500
csiph-web