[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Building paths & pygame.image.load documentation



Irv Kalb wrote:
But then I point out how Python solves this issue by allowing programmers to use the "/" character as the folder separator character - and how Python maps that character into the appropriate character for the operating system on which the program is running.

This is WRONG. Python does no such thing. You are seriously
misleading your students by telling them this.

What's happening is that most Windows system functions
accept either forward or backward slashes as path separators.
So *most* of the time you can get away with using forward
slashes, but there are situations where that won't work.

the documentation says:

You should use |os.path.join()| for compatibility.

My question is: Is there any reason to do it this way?

It's the only way that's guaranteed to work on all platforms
in all situations, so it's a good habit to teach and to get
into.

Any reason NOT to use:
ball = pygame.image.load('images/ball.png')

If MacOSX, Linux and Windows are the only platforms the code
will be required to run on, this will probably work. But you
should point out to your students that you're taking a
shortcut by relying on this.

--
Greg