[Tutor] Would an OOP approach be simpler?

Jacob S. keridee at jayco.net
Wed Nov 10 03:16:39 CET 2004

Hi all!

>def checkIfDoesExist(weekstart):
>    if os.path.exists('./archives/wb%s' % weekstart):
>        done=file('./archives/wb%s/got.lst' %weekstart, 'rb')
>        donelist=done.readlines()
>        done.close()
>        list=donelist[0].split('/')
>        return (list, 1)
>    else:
>        return (None, 0)

Okay, three things.

1) Does this section of code do the same thing?

def checkIfDoesExist(weekstart):
    a = './archives/wb%s' % weekstart
    if os.path.exists(a):
        li = file(a,'rb').readlines()[0].split('/')
        return (li,1)
        return (None,0)

2) Do any of you advise against/for my modified code block?
3) Does li automatically close? The file seems accessible even though I
haven't explicitly closed it.

Thanks for answering these when you get around to it.
Jacob Schmidt

More information about the Tutor mailing list