[Tutor] a quick Q: how to use for loop to read a series of files with .doc end
lina
lina.lastname at gmail.com
Thu Sep 29 17:13:28 CEST 2011
mport os.path
tokens=['E']
result=[]
for fileName in os.listdir("."):
if os.path.isfile(fileName) and os.path.splitext(fileName)=="xpm":
filedata = open(fileName,'r')
text=filedata.readlines()
for line in text:
print line
why here I print nothing out?
There is .xpm file there with content.
Thanks,
On Thu, Sep 29, 2011 at 11:06 PM, lina <lina.lastname at gmail.com> wrote:
>
>
> On Thu, Sep 29, 2011 at 10:55 PM, lina <lina.lastname at gmail.com> wrote:
>
>> import os.path
>>
>> tokens=['E']
>> result=[]
>>
>>
>> for fileName in os.listdir("."):
>> if os.path.isfile(fileName) and os.path.splitext(fileName)=="xpm":
>> filedata = open(fileName)
>> text=filedata.readlines()
>> for line in text:
>>
>>
>> How can I read from line 24 and do further looking for "E".
>>
>> Thanks,
>>
>>
> The file starts from line 24 is something like
>
> aabbccddEaabb
> acbbddEbbaaca
> EabcEabcaaaa
> aEaaEaaaaaaa
>
> so for the first column, I can get 1 E, second column is also 1 E, third is
> 0, four is 2.
>
> namely count the occurence of E in each column.
>
> Thanks,
>
>
>>
>>
>> On Thu, Sep 29, 2011 at 10:43 PM, Dave Angel <d at davea.name> wrote:
>>
>>> On 09/29/2011 10:22 AM, lina wrote:
>>>
>>>> Hi,
>>>>
>>>> I want to read a bunch of *.doc file in present working directory,
>>>>
>>>> how can I use for to read one by one and do further work,
>>>>
>>>> sorry,
>>>>
>>>> what's the best reference webpage I can use?
>>>>
>>>> I googled, lots of distracting info, and I barely can understand how
>>>> they
>>>> think.
>>>>
>>>> THanks,
>>>>
>>>> Look in the os module for things like this. In particular (untested):
>>>
>>> import os.path
>>>
>>> for fileName in os.listdir(".")
>>> if os.path.isfile(fileName) and os.path.splitext(fileName) == "doc":
>>> filedata = open(fileName)
>>> xxxdosomething with filedata
>>>
>>>
>>>
>>> --
>>>
>>> DaveA
>>>
>>>
>>
>>
>> --
>> Best Regards,
>>
>> lina
>>
>>
>>
>
>
> --
> Best Regards,
>
> lina
>
>
>
--
Best Regards,
lina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110929/8df9629b/attachment.html>
More information about the Tutor
mailing list