[Tutor] How to get script to detect whether a file exists?

Hugo Arts hugo.yoshi at gmail.com
Mon Aug 2 01:01:47 CEST 2010


On Mon, Aug 2, 2010 at 12:53 AM, Richard D. Moores <rdmoores at gmail.com> wrote:
> On Sun, Aug 1, 2010 at 15:00, Richard D. Moores <rdmoores at gmail.com> wrote:
>> On Sun, Aug 1, 2010 at 14:44, Daniel Sarmiento <dsarmientos at gmail.com> wrote:
>>>
>
>>> Without knowing what your code does, I think it will be something like:
>>>
>>> try:
>>>     F_unused = open(path1, 'rb')
>>>     F_used = open(path2, 'rb')
>>> except IOError:
>>>     print("no")
>>>     .....
>>> else:
>>>     unused_ints = pickle.load(F_unused)
>
> OK. Did that. And it works: <http://tutoree7.pastebin.com/EDgwU6Ac>.
> Now what? Am I done? Or should I break it up into a bunch of
> functions, each one doing just one thing?
>

For a script this short, you could probably get away with just leaving
it here. However, I mean that in a "if you're really lazy, I suppose
you could" way. It will become easier to understand if you break it
up, and that is good for your future sanity. So it's not required, but
it definitely can't hurt, and if this script gets any larger you will
be glad you broke it up.

Hugo


More information about the Tutor mailing list