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


Groups > comp.lang.python > #99093

Re: How can I export data from a website and write the contents to a text file?

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Patrick Hess <patrickhess@gmx.net>
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 20:17:37 +0100
Lines 26
Message-ID <mailman.486.1447964619.16136.python-list@python.org> (permalink)
References <9365cf2f-e9c7-4338-83b4-ce3d1d7ce1d6@googlegroups.com> <6e0f470b-f896-43ae-8f83-b20f22a9db8d@googlegroups.com> <e0edf996-9ce8-404e-b4e0-1e9a7b9af706@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding 7Bit
X-Trace news.uni-berlin.de LoEdQfVNWDSKZuT0vqniTQGI6BpU4dFpqRbgMhROtNaw==
Return-Path <patrickhess@gmx.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:text': 0.04; 'binary': 0.05; 'mode:': 0.07; 'skip:o 50': 0.07; 'subject:file': 0.07; 'subject:How': 0.09; '"w")': 0.09; 'mode,': 0.09; 'received:gmx.net': 0.09; '"\\r\\n"': 0.16; '2")': 0.16; 'from:addr:gmx.net': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:export': 0.16; 'wrote:': 0.16; 'typing': 0.18; 'working.': 0.18; ';-)': 0.18; 'together.': 0.20; 'produces': 0.22; 'this:': 0.23; 'unix': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'patrick': 0.27; 'correct': 0.28; 'actual': 0.28; 'subject:website': 0.29; 'system,': 0.30; 'windows.': 0.33; 'open': 0.33; 'text': 0.35; 'mode': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'operating': 0.37; 'charset:us-ascii': 0.37; 'seem': 0.37; 'doing': 0.38; 'anything': 0.38; 'files': 0.38; 'subject:from': 0.39; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'received:212.227.17': 0.66; 'finally': 0.70; 'useful.': 0.72; 'subject:write': 0.84
User-Agent KMail/4.14.3 (FreeBSD/10.1-RELEASE-p24; KDE/4.14.3; i386; ; )
In-Reply-To <e0edf996-9ce8-404e-b4e0-1e9a7b9af706@googlegroups.com>
X-Provags-ID V03:K0:kcO1PgNoYtcbhpyVvFEyOhoO1cdsTSgVKEebF05oy8gkDBAnLbn mxu6wn681yXeXo9V2hbhMu2AswdGQVVxlxx6/DRd3HrO7p4UlKyQlGWf/kh6LpcdcsyP4o4 CKfIryd6Tb4R4mSIJOjU+5h2TCARTGOAycS8FAS+HUXKLUO17W+XCxZP/Q/nNOjPvUdALrT tJ3A97UaasRKQq4eo6g5Q==
X-UI-Out-Filterresults notjunk:1;V01:K0:rJsGNJp15aI=:Zp5eX3a5anoxo6LgJc9gU8 erjWK32yEaeAVd0D+JcIRDvLf5kEXx+IUH3wKi8ALxGhl9HiHU2fJAI7wZXw8wQnNfAYwHO9x UqhhaQ/Ma42jse3pgwy69GXhL+9NPcF9ukwnZSOWVpoS8b+QnviwBWAYWylFRMQgXr/+xFEXE An3/PjZvPZ/AdgsrQhDQROrHkkSDvhdWIK4kG948zwfVa/wXnIgRpcQ0RjChl9XJc8oBqilMV Hai8ZM6B4EVZKa56BHbjFWvBBcrAeyoOlkGklvuQepoFXWJjzgZE3aiLVflHHw/91VG8k281Q 4UF6E7NTgfkidj7o+CVhjKHEcQc6Eh4wTii7r67hcBpfI2JCNeXqb0++rmv71rb+uUp0Cuefn IdBz7t+TwsXhOuSd8r3WZnu3tGYLKSrx/n9QrChJ+700Vg8LtsTcuG53DTLT1F8AxL/+enKcf atbmAsDQJmnNuCmcrtvIMU//cAPySC9EPjsLpFDM40GvLr+rAYTU+dFDM2XPTFYeQQBFMdON8 UM5X0P5dSmhXwhaH7xdGLjm7SAnSk58veBYXGc9F9WxfYISPL6tc8e+W+PqH5zf7ngAxLyhb3 7p0lsz/w/fUU7oehpL1rJO60JCIxTB8IGNNEDMlxtYTJvlhUhiWHtJUs9nw8GHFSW+1aWt7p8 EzgBEg9iyNwSn/d/4TK3WYKMwcDRnn07i3VNmnSmdeQ8dakrJyw7Si7EXIw58zH0NZM84WbUv v9Od5TctZltUI43GFU1aIw/8I6RjgbocEopFNKZ2pRby6NsQCS2PyRMZPUJ4rgnZBsEpymTKI pBmYzWP
X-Mailman-Approved-At Thu, 19 Nov 2015 15:23:37 -0500
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:99093

Show key headers only | View raw


ryguy7272 wrote:
> text_file = open("C:/Users/rshuell001/Desktop/excel/Text1.txt", "wb")
> [...]
> It doesn't seem like the '\n' is doing anything useful.  All the text is jumbled together.
> [...]
> I finally got it working.  It's like this:
> "\r\n"

The better solution would be to open text files in actual text mode:

    open("filename", "wb")   # binary mode
    open("filename", "w")    # text mode

In text mode, the correct line-ending characters, which will vary
depending on the operating system, are chosen automatically.

    with open("test.txt", "w") as textfile:
        textfile.write("line 1\n")
        textfile.write("line 2")

This produces "line 1\nline 2" on Unix systems and "line 1\r\nline 2"
on Windows.

Also involves less typing this way. ;-)

Patrick

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


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