[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:25:19 CEST 2011


On Thu, Sep 29, 2011 at 11:18 PM, Walter Prins <wprins at gmail.com> wrote:

>
>
> On 29 September 2011 16:13, lina <lina.lastname at gmail.com> wrote:
>
>> 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,
>>
>>
> Is your .xpm files actually text files?  Or are they binary (e.g. maybe
> graphics) files?  (XPM is normally the extension of a graphics filetype.)
> Treating a binary file as if its text is not liable to work very well.
>
> Also can you please confirm whether this task is homework/study related?
>

I have some awk script to achieve this. I can assure you it's not homework.
LOL ... I have never attended some python course.
sometimes it's hard for you to image how hard I persuade myself to use/think
in python way, forget what is-already-relatively-easy-for-me-to-use bash
script.

the xpm file an read, I just text

f=open('1.xpm','r')
for line in f.readlines():
    print line
f.close()

I am google-ing how to get the line index, so will use those after 24.


>
> Walter
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Best Regards,

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


More information about the Tutor mailing list