Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70564
| From | Dave Angel <davea@davea.name> |
|---|---|
| Subject | Re: how to write list in a file |
| Date | 2014-04-23 21:45 -0400 |
| Organization | news.gmane.org |
| References | <CAPxp-0R8dSR8wzcn=cCTnHMJ=qb7Ryocyi11qAM+VVufzCVVzA@mail.gmail.com> <lj9jlg$eub$1@ger.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9478.1398303588.18130.python-list@python.org> (permalink) |
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
Re: how to write list in a file Dave Angel <davea@davea.name> - 2014-04-23 21:45 -0400
csiph-web