[Tutor] a quick Q: how to use for loop to read a series of files with .doc end
lina.lastname at gmail.com
Sat Oct 8 15:18:36 CEST 2011
On Sat, Oct 8, 2011 at 6:27 PM, Alan Gauld <alan.gauld at btinternet.com>wrote:
> On 08/10/11 04:34, lina wrote:
> print(summary) ### output is [1,3,5,6]
> This line is wrong.
> This is converting summary to a string -> '[1,3,5,6]'
> Then splitting by commas to create a new list -> [ '[1', '3', '5', 6]' ]
> Notice the first and last elements have the 
> Then it joins then into a string using \n as seperators.
> What you want, I think, is to join the original list
> with spaces(and maybe add a newline for writing to file)
You are right!
> summary = ' '.join(summary) + \n
> Just correct.
> with open(base+OUTFILEEXT,"w") as f:
Thanks, it's helpful.
> Alan G
> Author of the Learn to Program web site
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor