[Tutor] a quick Q: how to use for loop to read a series of files with .doc end

lina lina.lastname at gmail.com
Wed Oct 5 16:15:08 CEST 2011


<snip>

> I ask again.  What did results look like when you print it out.  I'm
> referring to the argument to writeonefiledata().
>
>> def writeonefiledata(outname,**results):
>>
> put the lines here:
>            print ("results is: ", results)
>            print("repr is:", repr(results))

 $ python3 counter-vertically-v2.py
results is: {'B': [0, 0, 0, 0, 0, 0], 'E': [2, 1, 4, 0, 1, 0]}
repr is: {'B': [0, 0, 0, 0, 0, 0], 'E': [2, 1, 4, 0, 1, 0]}


>
>      outfile = open(outname,"w")
>>     for item in results:
>>         return outfile.write(item)
>>
>> This final part I made some mistakes?
>>
>>  yes, you're iterating over the keys of a dictionary.  Since it only has
> the key "E", that's what you get.  Try printing dir(results) to see what
> methods might return something other than the key.  Make the language work
> for you.

Sorry I am not smart.  value?

>
>
> DaveA
>
>


-- 
Best Regards,

lina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111005/ecd93acc/attachment.html>


More information about the Tutor mailing list