how to write list in a file

Dave Angel davea at davea.name
Wed Apr 23 21:45:38 EDT 2014


Terry Reedy <tjreedy at 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




More information about the Python-list mailing list