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


Groups > comp.lang.python > #70564

Re: how to write list in a file

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.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; 'paths': 0.07; 'subject:file': 0.07; 'filename': 0.09; 'latter': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'wrote': 0.14; 'absolute,': 0.16; 'cwd': 0.16; 'dhananjay': 0.16; 'opened.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'trying': 0.19; 'everyone,': 0.19; "i've": 0.25; 'script': 0.25; 'header:X-Complaints-To:1': 0.27; 'am,': 0.29; 'relative': 0.30; 'subject:list': 0.30; "user's": 0.31; 'file': 0.32; 'actual': 0.34; 'anywhere': 0.35; 'operations': 0.35; 'should': 0.36; 'too': 0.37; 'list': 0.37; 'being': 0.38; 'problems': 0.38; 'follows:': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'even': 0.60; 'strictly': 0.61; "you're": 0.61; 'real': 0.63; 'started.': 0.68
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re: how to write list in a file
Date Wed, 23 Apr 2014 21:45:38 -0400 (EDT)
Organization news.gmane.org
References <CAPxp-0R8dSR8wzcn=cCTnHMJ=qb7Ryocyi11qAM+VVufzCVVzA@mail.gmail.com> <lj9jlg$eub$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host dpc6744195189.direcpc.com
X-Newsreader PiaoHong.NewsGroup.Client.VIP:1.52
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 <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>
Newsgroups comp.lang.python
Message-ID <mailman.9478.1398303588.18130.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1398303588 news.xs4all.nl 2898 [2001:888:2000:d::a6]:46218
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:70564

Show key headers only | View raw


Terry Reedy <tjreedy@udel.edu> Wrote in message:
> On 4/23/2014 3:53 AM, Dhananjay wrote:
>> Hello everyone,
>>
>> I am trying hard to write a list to a file as follows:
>>
>>
>> def average_ELECT(pwd):
>>      os.chdir(pwd)
> 
> I would 'print pwd' to make sure where files are being opened.
> 
>>      files = filter(os.path.isfile, os.listdir('./'))
>>      

I wouldn't.  I've seen too many flaky problems to trust os.chdir
 in real code.  I think the op should build each filename with
 os.path.append or similar. All paths used for actual file
 operations should either be absolute,  or strictly relative to
 the user's cwd when the script started.  And even the latter is
 suspect when you're anywhere near Windows. 

-- 
DaveA

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


Thread

Re: how to write list in a file Dave Angel <davea@davea.name> - 2014-04-23 21:45 -0400

csiph-web