Now, Now!
Patience, I will show you why
you got the path /data/... it is because the OS.Path gives you the location you
are in and that is the unprinted default and adds onto that the print-out you
got on the screen for that was the join part of the path and only the join part
of the path...
fullname = os.path.join('data',
name)
self.image, self.rect =
load_image('chimp.bmp', -1)
NOTE: Then name in parenthesis is the
chimp.bmp. In other words the variable with
that name inside, pointing to it.
SO: os.path.join(... will be the path you reside in at the time you ran your
program. In other words that will be the c:\python25\ directory. Or if you are
in examples it would be c:\python25\examples. But since you can not find that
file name it is because you are not in the examples folder.
NOW:
Since you have placed
the Chimp.py file in your Python25 directory you must now locate the data
directory which is mentioned in the program below and copied above for this
example. Remember the only thing mentioned in the program after the join
statement is /dat/ which is correct for the file is in the data folder, but, you
are not in the examples folder where the data folder resides. You are in the
Python25 folder or directory where the examples directory or folder
resides.
Thus, you either change the join
statement to include the examples folder or move into the examples folder and
run from there. Which is what the batch file does. It places you into the
examples folder to run the Chimp.py module. Which when running it is running
from the examples folder and not the Python25 folder, so the os.path will
have inside of it c:/Python25/examples/ and the join will append onto it, join,
the path inside the '...' or data/
Now my example or batch file is
placing you into the folder you wish to be in. The examples folder has example
programs. The data folder has data for these games/programs/modules.
so the batch file starts you in
the Python25 folder, jumps you into the examples folder, then runs the Chimp.py
from that folder. Once you exit the game you go back inside the batch file which
has a CD .. or CD c:\python25 command to move back to the previous directory or
the the python directory...
In other words the command CD ..
means move back one directory, or folder.
FINALLY:
I gave you the batch file to use
that you can use anywhere inside any folder. A batch file with no path and the
name for that batch file can be named to correspond to what you wish to run.
Like EX.BAT for example programs and will jump into examples folder if you wish
to start and remain inside the Python25 folder. Having no path inside of the
batch file allows you to be anywhere and go anywhere. By deleting the CD .. at
the end means you wish to stay in that folder so it is dependent on what you
intend to do.
Now in the batch file I added %1
%2 %3 ... these correspond to any added switches or commands placed on the
command line before hitting enter to run the program from the batch file. If
they are blank then nothing gets passed. But %1 must be there for the name of
the file you wish to run in Python.
ALSO:
The downloadable program he
mentions is a program that gets placed into your MY Computer or Explorer file
menu or context menu. It says Open Command Here when you cursor down the file or
context menu. Click on it when hovering over the folder, such as the examples
folder, it will take you to DOS right at that point and you will be right inside
the examples folder.
This is an easy way as long as
the DOS folder you wish to be in is located by the system path for the Python25
executable. But that should not be a problem as long as the system path points
to the Python25.exe file. He did give you an example to set it and I think you
probably do have it already for the downloads now automatically set it up for
you. but if not, then change it as he suggested.
For the system path is needed to
run programs and when using the download he gives you will be able to go into
any folder you desire to run DOS from. When you type exit you just go back to
the last Windows command or window you were in, unless you closed it to clear
the screen.
So please decide on what you
wish to do. My batch file below if copied into the folder you wish to be in then
give it any name to correspond to what you wish to do. My batch file below has
to reside in the folder you have the .py file in. The other example I will add
below it and that will allow you to be in the Python25 folder and jump into any
folder beneath it or if you wish to go somewhere else then you will have to add
the path to it. The second example will just jump you into the example folder
and back out or up to the Python25 folder above it. Or parent of the child
folder.
The name you place on the batch file can be like I
did below P.BAT for a Python load and run, or EX.BAT to load Python25 and run a
.py name you give on the command line from the Python25 folder into
the examples folder. I used short names just to make it easier for you to
type and get into your program to run.
I hope this helps,
Bruce
On 10/31/07, RR4CLB
< chester_lab@xxxxxxxxxxxx>
wrote:
|