Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #99174
| Path | csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Michael Torrie <torriem@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 | Fri, 20 Nov 2015 10:44:00 -0700 |
| Lines | 23 |
| Message-ID | <mailman.12.1448041450.2291.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> <2052054.MEiq1cOQgg@desk8.phess.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252 |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de bvsv4PAFmC4o9E2gOyxkJwjJgkraff1HQExNfI45HcEw== |
| Return-Path | <torriem+gmail@torriefamily.org> |
| 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; 'python3': 0.05; 'mode:': 0.07; 'skip:o 50': 0.07; 'subject:file': 0.07; 'subject:How': 0.09; '"w")': 0.09; 'essential.': 0.09; 'mode,': 0.09; 'encoding': 0.15; 'subject: \n ': 0.15; '"\\r\\n"': 0.16; 'default).': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:export': 0.16; 'wrote:': 0.16; 'working.': 0.18; 'together.': 0.20; 'this:': 0.23; 'header:In- Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'patrick': 0.27; 'specify': 0.27; 'correct': 0.28; 'idea': 0.28; 'actual': 0.28; 'subject:website': 0.29; 'system,': 0.30; 'open': 0.33; 'message-id:@gmail.com': 0.34; 'text': 0.35; 'unicode': 0.35; 'mode': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'operating': 0.37; 'received:org': 0.37; 'seem': 0.37; 'doing': 0.38; 'anything': 0.38; 'files': 0.38; 'subject:from': 0.39; 'subject:the': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'charset:windows-1252': 0.62; 'matter': 0.63; 'finally': 0.70; 'wish': 0.71; 'useful.': 0.72; 'subject:write': 0.84 |
| X-Virus-Scanned | amavisd-new at torriefamily.org |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 |
| In-Reply-To | <2052054.MEiq1cOQgg@desk8.phess.net> |
| 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:99174 |
Show key headers only | View raw
On 11/19/2015 12:17 PM, Patrick Hess wrote:
> 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.
It's not just a matter of line endings. It's a matter of text encoding
also. This is critical in Python3 where everything is unicode and
encoding is essential. You have to to use the text mode when writing
files here, and it's also a good idea to specify what encoding you wish
to write with (UTF-8 is a good default).
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