[Tutor] How to get script to detect whether a file exists?
Richard D. Moores
rdmoores at gmail.com
Mon Aug 2 02:26:41 CEST 2010
On Sun, Aug 1, 2010 at 16:01, Hugo Arts <hugo.yoshi at gmail.com> wrote:
> 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.
Well, I'd like to try. Could you give me, say, an outline of what
might be a good way? Actually, before I changed to the error catching,
I tried to break it up into a bunch of small functions. But they got
all tangled up with some functions returning the calling of others,
that I couldn't get them straightened out. Also, some were required to
have such a long string of arguments I couldn't get them all on one
line.
Dick
>
> Hugo
>
More information about the Tutor
mailing list