Print from P3D?[SOLVED]

Is there a way to make a p3d print something out to the command line or the log file, or do I just need to write some output to a file manually?

The reason I ask is because my program is working fine until I package it up in a p3d. When I run the p3d, I’m getting an “index out of range” error on a list generated from a text file. I want to be able to look at exactly what I’m getting from the text file and why my fail-safes against that sort of thing aren’t going into effect. Normally I’d just use the print statement, but I’m not seeing any output from that in either the session or the core logs, and if it’s printing to the command prompt the prompt is closing before I can read it.

Open a command shell, and run the p3d file from that with “panda3d myfile.p3d”. Then you’ll be able to view the Python output after it closes. Or you can even dump it to a file with “panda3d -l mylog.txt myfile.p3d”.

If your p3d file is embedded in a web page, this happens automatically; but if it is run from the desktop, the output is lost unless you do the above. That’s arguably a mistake; the output should probably be routed to a log file by default when you run from the desktop.


Start the p3d from the command line? Or you can simple use use open. The file will be placed at the host directory of panda3d (in my case C:\Users\Nox\AppData\Local\Panda3D\start).

Found the problem. All the text files have had the \r newline character for other OSes added to them. I need to account for that. Thanks for the help.

Hmm, if you open the text file with something like open(‘filename’, ‘rU’), it should activate the universal EOL conversion, so that you read only \n, never \n\r, from the text file. Actually, when running in a p3d file, the U is implicit as long as you don’t specify ‘rb’.

Is that not working?


I’m using “r” in all my open statments (except for the ones using “w”, of course). My files only have “\n” characters. Whenever I open a file I read the lines into a list with readlines() and then iterate through the list using strip("\n") to remove the end line characters. If I print the result when running my code prior to packaging, the lines are clean. When I print the result when running the p3d, every line has a “\r” at the end.

That’s about all I can tell you.

Hmm, you’re right. I’ll investigate further.


For the moment, I changed all of my lines that strip “\n” to “\n\r” and now my game runs from p3d and also when I create an installer for it with pdeploy. I know that doesn’t solve the overall issue you’re looking to deal with, but it does make me happy. Thanks again for the help.