[Tutor] Re: Sample9.py and Sample9.pyc & seting path to Python open files ...

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Nov 26 03:40:50 EST 2003

> About Danny written: "Show us the code, and we can take a look" -
> honestly, it doesn't deserve to be called "code". There are just some
> basic "learning lines", just to become familiar with read/write
> functions, options, etc., so I think, it wouldn't mean any help to you.

Hi Tadey,

You're being too hard on yourself.  Let us decide the usefulness or
uselessness of the program for ourselves.

There are good reasons for showing us the code.  For one, it helps you
practice giving good bug reports.  *grin*

Seriously, from a purely practical perspective, if you don't show us your
program, all we can do is make vague guesses at what is causing the
problem.  At the moment, I have to wildly guess that there's a problem in
the line that open()s the file, but that's as far as I can see without

> I was just attending to write something more "complex".
> And also I haven't got poblems processing this code, but already opening
> file, so I assume the problem is not in the code ...

Yes, that's what you're assuming.  But, frankly, if you don't have
problems in your program, then that program should be working perfectly.

The first rule about debugging is not to assume, without strong proof,
that code is correct.  And even if the problem isn't in the code itself,
once we see what you've done so far, then given the context of the
problem, we can give you better suggestions to further diagnose things.

For example, if you had shown us something like the line:

    f = open("hello.txt")

then that would have immediately given us some avenues of attacking the
problem.  Perhaps the current working directory is different today than
yesterday.  If that's the problem, then we'd ask what would happen if we
hardcode the absolute path name during the open(), like:

    f = open("D:/Program Files/Python/Lib/idlelib/Saves/hello.txt")

Or if you had shown us something like:

    f = open("D:\Program Files\Python\Lib\idlelib\Saves\hello.txt")

then we could have warned you about the potential problems with
backslashes in strings.

Programming is a difficult thing: it's both a high-level and low-level
activity, and bugs can come in from both directions.  Summarizing the
situtation --- that you're getting an error message when opening a file
--- is a great thing to do.  But equally good is to show the lines that
are causing the problem.

I apologize about being pedantic about this. *grin* But when you're asking
for help, you need to show us what you're doing.  There's a real value to
showing us what you've typed, and how Python responds to your program.
And aon't worry if the code is "simple", because that's perfectly ok to
us: we like looking at simple code.

Best of wishes to you!

More information about the Tutor mailing list