Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51086
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <vincent.vandevyvre@swing.be> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'resulting': 0.04; 'url:launchpad': 0.05; '-*-': 0.07; 'utf-8': 0.07; 'string': 0.09; 'coding:': 0.09; 'if,': 0.09; 'indeed,': 0.09; 'newline': 0.09; 'windows,': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'windows': 0.15; "'w')": 0.16; '23,': 0.16; 'carriage': 0.16; 'cc:name:python list': 0.16; 'dump': 0.16; 'from:addr:swing.be': 0.16; 'from:addr:vincent.vandevyvre': 0.16; 'from:name:vincent vande vyvre': 0.16; 'line),': 0.16; 'message-id:@swing.be': 0.16; 'newlines': 0.16; 'oqapy': 0.16; 'paqager': 0.16; 'received:mobistar.be': 0.16; 'url:oqapy': 0.16; 'url:paqager': 0.16; 'url:qarte': 0.16; 'v.v.': 0.16; '\xe9crit': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'bit': 0.19; 'file,': 0.19; 'later': 0.20; 'seems': 0.21; '>>>': 0.22; 'example': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'replace': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'source': 0.25; 'script': 0.25; 'changes,': 0.26; 'this:': 0.26; 'code:': 0.26; 'somewhere': 0.26; 'header:In-Reply-To:1': 0.27; 'skip:- 40': 0.29; 'am,': 0.29; 'unix': 0.29; 'characters': 0.30; 'compared': 0.30; 'converting': 0.30; 'dos': 0.30; 'code': 0.31; '(since': 0.31; 'equivalent.': 0.31; 'strip': 0.31; 'txt': 0.31; 'file': 0.32; 'skip:- 30': 0.32; 'text': 0.33; 'open': 0.33; 'screen': 0.34; 'subject:with': 0.35; 'created': 0.35; 'problem.': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'sequence': 0.36; 'doing': 0.36; 'should': 0.36; 'two': 0.37; 'skip:o 20': 0.38; 'jason': 0.38; 'files': 0.38; 'hope': 0.61; 'first': 0.61; "you've": 0.63; 'therefore,': 0.64; 'more': 0.64; 'jul': 0.74; 'ending': 0.78; 'whereas': 0.91; 'to:none': 0.92; 'imagine': 0.93; '2013': 0.98 |
| Date | Tue, 23 Jul 2013 15:10:35 +0200 |
| From | Vincent Vande Vyvre <vincent.vandevyvre@swing.be> |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 |
| MIME-Version | 1.0 |
| CC | python list <python-list@python.org> |
| Subject | Re: Strange behaviour with os.linesep |
| References | <gksnu85fe69utl50s4e1tik0bhinndls3m@4ax.com> <mailman.4956.1374418117.3114.python-list@python.org> <pb2ou8577r2ahshc0h3oeqoe25dei9gv1o@4ax.com> <mailman.4966.1374428821.3114.python-list@python.org> <hbhou89g1ie8igtrpl24ajibc2251ea1po@4ax.com> <mailman.4969.1374452915.3114.python-list@python.org> <368qu85msgfhuk2j2s13qj0bqn4rkcint9@4ax.com> <mailman.4973.1374496190.3114.python-list@python.org> <at9qu8tq4gbp5rfgd7mq2eo8ui6uh3vnvg@4ax.com> <CAPTjJmrVChLrcAZvDj4frqEFiy=gJzKP3mGnCRxkM6t6euxcVQ@mail.gmail.com> <51ED3CEB.1070706@gmail.com> <mailman.4980.1374502532.3114.python-list@python.org> <XnsA2065B2C39831duncanbooth@127.0.0.1> <mailman.4997.1374571174.3114.python-list@python.org> <XnsA2067049ADEF7duncanbooth@127.0.0.1> <51EE6C15.5070701@swing.be> <CAEk9e3o+ddin5OJAUiSaP0ORuedWQToqQuJypwz_yPeJSO1OVQ@mail.gmail.com> |
| In-Reply-To | <CAEk9e3o+ddin5OJAUiSaP0ORuedWQToqQuJypwz_yPeJSO1OVQ@mail.gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5005.1374585496.3114.python-list@python.org> (permalink) |
| Lines | 105 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1374585496 news.xs4all.nl 15890 [2001:888:2000:d::a6]:32924 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:51086 |
Show key headers only | View raw
Le 23/07/2013 14:39, Jason Swails a écrit :
>
>
>
> On Tue, Jul 23, 2013 at 7:42 AM, Vincent Vande Vyvre
> <vincent.vandevyvre@swing.be <mailto:vincent.vandevyvre@swing.be>> wrote:
>
> On Windows a script where de endline are the system line sep, the
> files are open with a double line in Eric4, Notepad++ or Gedit but
> they are correctly displayed in the MS Bloc-Notes.
>
> Example with this code:
> ----------------------------------------------
> # -*- coding: utf-8 -*-
>
> import os
> L_SEP = os.linesep
>
> def write():
> strings = ['# -*- coding: utf-8 -*-\n',
> 'import os\n',
> 'import sys\n']
> with open('writetest.py', 'w') as outf:
> for s in strings:
> outf.write(s.replace('\n', L_SEP))
>
>
> I must ask why you are setting strings with a newline line ending only
> to replace them later with os.linesep. This seems convoluted compared
> to doing something like
>
> def write():
> strings = ['#-*- coding: utf-8 -*-', 'import os', 'import sys']
> with open('writetest.py', 'w') as outf:
> for s in strings:
> outf.write(s)
> outf.write(L_SEP)
>
> Or something equivalent.
>
> If, however, the source strings come from a file you've created
> somewhere (and are loaded by reading in that file line by line), then
> I can see a problem. DOS line endings are carriage returns ('\r\n'),
> whereas standard UNIX files use just newlines ('\n'). Therefore, if
> you are using the code:
>
> s.replace('\n', L_SEP)
>
> in Windows, using a Windows-generated file, then what you are likely
> doing is converting the string sequence '\r\n' into '\r\r\n', which is
> not what you want to do. I can imagine some text editors interpreting
> that as two endlines (since there are 2 \r's). Indeed, when I execute
> the code:
>
> >>> l = open('test.txt', 'w')
> >>> l.write('This is the first line\r\r\n')
> >>> l.write('This is the second\r\r\n')
> >>> l.close()
>
> on UNIX and open the resulting file in gedit, it is double-spaced, but
> if I just dump it to the screen using 'cat', it is single-spaced.
>
> If you want to make your code a bit more cross-platform, you should
> strip out all types of end line characters from the strings before you
> write them. So something like this:
>
> with open('writetest.py', 'w') as outf:
> for s in strings:
> outf.write(s.rstrip('\r\n'))
> outf.write(L_SEP)
>
> Hope this helps,
> Jason
The '\n' are in the original file.
I've tested these other versions:
-------------------------------
def write():
strings = ['# -*- coding: utf-8 -*-\n',
'import os\n',
'import sys\n']
with open('writetest.py', 'w') as outf:
txt = L_SEP.join([s.rstip() for s in strings]):
outf.write(txt)
------------------------------
-------------------------------
def write():
strings = ['# -*- coding: utf-8 -*-',
'import os',
'import sys']
with open('writetest.py', 'w') as outf:
txt = L_SEP.join( strings):
outf.write(txt)
------------------------------
Las, no changes, always correctly displayed in MS bloc-notes but with
double line in other éditors.
--
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Simple Python script as SMTP server for outgoing e-mails? Gilles <nospam@nospam.com> - 2013-07-21 16:42 +0200
Re: Simple Python script as SMTP server for outgoing e-mails? Chris Angelico <rosuav@gmail.com> - 2013-07-22 00:48 +1000
Re: Simple Python script as SMTP server for outgoing e-mails? Gilles <nospam@nospam.com> - 2013-07-21 18:19 +0200
Re: Simple Python script as SMTP server for outgoing e-mails? Michael Torrie <torriem@gmail.com> - 2013-07-21 11:46 -0600
Re: Simple Python script as SMTP server for outgoing e-mails? Gilles <nospam@nospam.com> - 2013-07-21 22:34 +0200
Re: Simple Python script as SMTP server for outgoing e-mails? Ivan Shmakov <oneingray@gmail.com> - 2013-07-21 20:53 +0000
Re: Simple Python script as SMTP server for outgoing e-mails? Michael Torrie <torriem@gmail.com> - 2013-07-21 18:28 -0600
Re: Simple Python script as SMTP server for outgoing e-mails? Gilles <nospam@nospam.com> - 2013-07-22 14:11 +0200
Re: Simple Python script as SMTP server for outgoing e-mails? Chris Angelico <rosuav@gmail.com> - 2013-07-22 22:29 +1000
Re: Simple Python script as SMTP server for outgoing e-mails? Gilles <nospam@nospam.com> - 2013-07-22 14:38 +0200
Re: Simple Python script as SMTP server for outgoing e-mails? Chris Angelico <rosuav@gmail.com> - 2013-07-22 22:51 +1000
Re: Simple Python script as SMTP server for outgoing e-mails? Michael Torrie <torriem@gmail.com> - 2013-07-22 08:08 -0600
Re: Simple Python script as SMTP server for outgoing e-mails? Chris Angelico <rosuav@gmail.com> - 2013-07-23 00:15 +1000
Re: Simple Python script as SMTP server for outgoing e-mails? Duncan Booth <duncan.booth@invalid.invalid> - 2013-07-23 08:06 +0000
Re: Simple Python script as SMTP server for outgoing e-mails? Chris Angelico <rosuav@gmail.com> - 2013-07-23 19:19 +1000
Re: Simple Python script as SMTP server for outgoing e-mails? Duncan Booth <duncan.booth@invalid.invalid> - 2013-07-23 10:06 +0000
Strange behaviour with os.linesep Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2013-07-23 13:42 +0200
Re: Strange behaviour with os.linesep Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-23 15:25 +0000
Re: Strange behaviour with os.linesep Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-07-23 19:41 -0400
Re: Strange behaviour with os.linesep Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-07-23 19:51 -0400
Re: Strange behaviour with os.linesep Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2013-07-24 09:02 +0200
Re: Strange behaviour with os.linesep Chris Angelico <rosuav@gmail.com> - 2013-07-24 17:39 +1000
Re: Strange behaviour with os.linesep Terry Reedy <tjreedy@udel.edu> - 2013-07-24 12:01 -0400
Re: Strange behaviour with os.linesep Jason Swails <jason.swails@gmail.com> - 2013-07-23 08:39 -0400
Re: Strange behaviour with os.linesep Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2013-07-23 15:10 +0200
Re: Strange behaviour with os.linesep Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2013-07-23 15:26 +0200
Re: Strange behaviour with os.linesep Jason Swails <jason.swails@gmail.com> - 2013-07-23 09:35 -0400
Re: Simple Python script as SMTP server for outgoing e-mails? Chris Angelico <rosuav@gmail.com> - 2013-07-24 07:37 +1000
Re: Simple Python script as SMTP server for outgoing e-mails? Chris Angelico <rosuav@gmail.com> - 2013-07-23 19:30 +1000
[OT] SPF - was Re: Simple Python script as SMTP server for outgoing e-mails? Michael Torrie <torriem@gmail.com> - 2013-07-23 09:12 -0600
Re: [OT] SPF - was Re: Simple Python script as SMTP server for outgoing e-mails? Chris Angelico <rosuav@gmail.com> - 2013-07-24 07:47 +1000
non sequitur: [OT] SPF - was Re: Simple Python script as SMTP server for outgoing e-mails? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-07-23 19:59 -0400
Re: non sequitur: [OT] SPF - was Re: Simple Python script as SMTP server for outgoing e-mails? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-24 01:42 +0000
Re: Simple Python script as SMTP server for outgoing e-mails? Sanjay Arora <sanjay.k.arora@gmail.com> - 2013-08-05 18:43 +0530
Re: Simple Python script as SMTP server for outgoing e-mails? Michael Torrie <torriem@gmail.com> - 2013-07-22 10:25 -0600
Re: Simple Python script as SMTP server for outgoing e-mails? Chris Angelico <rosuav@gmail.com> - 2013-07-23 02:32 +1000
Re: Simple Python script as SMTP server for outgoing e-mails? "Eric S. Johansson" <esj@harvee.org> - 2013-07-22 08:54 -0400
Re: Simple Python script as SMTP server for outgoing e-mails? Gilles <nospam@nospam.com> - 2013-07-23 23:48 +0200
Re: Simple Python script as SMTP server for outgoing e-mails? Michael Torrie <torriem@gmail.com> - 2013-07-22 08:10 -0600
Re: Simple Python script as SMTP server for outgoing e-mails? Gilles <nospam@nospam.com> - 2013-07-23 23:50 +0200
Re: Simple Python script as SMTP server for outgoing e-mails? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-07-21 12:39 -0400
Re: Simple Python script as SMTP server for outgoing e-mails? Grant Edwards <invalid@invalid.invalid> - 2013-07-21 21:01 +0000
Re: Simple Python script as SMTP server for outgoing e-mails? Gilles <nospam@nospam.com> - 2013-07-22 14:13 +0200
Re: Simple Python script as SMTP server for outgoing e-mails? Gilles <nospam@nospam.com> - 2013-07-22 14:19 +0200
Re: Simple Python script as SMTP server for outgoing e-mails? Grant Edwards <invalid@invalid.invalid> - 2013-07-22 14:10 +0000
Re: Simple Python script as SMTP server for outgoing e-mails? Michael Torrie <torriem@gmail.com> - 2013-07-22 08:21 -0600
Re: Simple Python script as SMTP server for outgoing e-mails? Chris Angelico <rosuav@gmail.com> - 2013-07-23 02:12 +1000
Re: Simple Python script as SMTP server for outgoing e-mails? Nobody <nobody@nowhere.com> - 2013-07-22 21:32 +0100
Re: Simple Python script as SMTP server for outgoing e-mails? Kevin Walzer <kw@codebykevin.com> - 2013-07-22 10:14 -0400
Re: Simple Python script as SMTP server for outgoing e-mails? Gilles <nospam@nospam.com> - 2013-07-23 23:53 +0200
Re: Simple Python script as SMTP server for outgoing e-mails? Kevin Walzer <kw@codebykevin.com> - 2013-07-24 10:38 -0400
Re: Simple Python script as SMTP server for outgoing e-mails? Gilles <nospam@nospam.com> - 2013-08-01 16:15 +0200
Re: Simple Python script as SMTP server for outgoing e-mails? Wayne Werner <wayne@waynewerner.com> - 2013-08-03 06:47 -0500
Re: Simple Python script as SMTP server for outgoing e-mails? Gilles <nospam@nospam.com> - 2013-08-06 12:44 +0200
Re: Simple Python script as SMTP server for outgoing e-mails? Kevin Walzer <kw@codebykevin.com> - 2013-08-03 21:41 -0400
Re: Simple Python script as SMTP server for outgoing e-mails? Gilles <nospam@nospam.com> - 2013-08-06 12:45 +0200
csiph-web