[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 18:07:00 CEST 2011


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

> Hi,
>
> On 29 September 2011 16:39, lina <lina.lastname at gmail.com> wrote:
>
>>
>> Or you can get lines 24-28, with  text[24, 29]   (look up slices in the
>>> Python doc)
>>>
>>
> Dave probably meant: text[24:29]
>
>
>
>>  >>> print splitext.__doc__
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> NameError: name 'splitext' is not defined
>> >>> print slices.__doc__
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> NameError: name 'slices' is not defined
>> >>> print slices._doc_
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> NameError: name 'slices' is not defined
>>
>
> You should probably be looking in the documentation, not trying to feed it
> into the interpreter.  (If you want to get help on a specific entity in
> Python it's usually better to use the "help()" function, e.g:
>
> >>> import os.path
> >>> help (os.path.splitext)
> Help on function splitext in module ntpath:
>
> splitext(p)
>     Split the extension from a pathname.
>
>     Extension is everything from the last dot to the end, ignoring
>     leading dots.  Returns "(root, ext)"; ext may be empty.
>
> >>>
>
> Note, trying to do "help(os.path.splitext)" would not have worked before I
> imported the "os.path" module.  (Differently put: Whatever you want to get
> help() on, must be known to the interpreter, so must either be built in or
> previously imported.)
>
> Walter
>
>
> Thanks all for your time,

I found one thing a bit weird, Here is the one:

import os.path

tokens=['E']
result=[]

"""
for fileName in os.listdir("."):
    if os.path.isfile(fileName) and os.path.splitext(fileName)[1]==".xpm":
"""
filedata = open("1.xpm")
text=filedata.readlines()
for line in text[23]:
    print line

1] $ python try2.py | wc -l
206

now changed to:
for line in text[23:24]:
    print line

2] $ python try2.py | wc -l
2

for line in text[23:25]:
    print line

3] $ python try2.py | wc -l
4

the situation 1 is supposed to be 1, while it's 206, it's just tilted 90
degree of this one line, kind of split. (if I am right here).
2] is correct.
3] is supposed to be 3, right, why it's 4?

and I want to check the correctness before using
for line in text[23:len(text)-1]:
    print line

I upload the 1.xpm in below link, really appreciate for the guidance.

https://docs.google.com/leaf?id=0B93SVRfpVVg3NzQxNWU4ZjktNzkwZi00ZDI5LWI1YzAtZTBkZGUzNzJmNGJh&sort=name&layout=list&num=50

-- 
Best Regards,

lina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110930/91bba7f0/attachment-0001.html>


More information about the Tutor mailing list