Load other Scripts in Python

Ok, serious noob question here. In Lua, you can use other files by calling

include "file.lua"

or something like that. But for the life of me, I can’t find any kind of documentation on how to do something like that in Python.

An example of why I would need this is if I was to make a class, it would be easier for me to write it separately from my main program given my C++/C#(BS, it’s Java in disguise) background. Speaking of OOP, I must say that I am impressed by how intuitive Python is when it comes down to OOP. Actually scares me a bit.

Oh yeah, and if that is even possible, would these files be automatically packed when I create the distributable exe or not? I’m surprised that the documentation didn’t cover that. :open_mouth:

In Lua, you can use other files by calling

include "file.lua"

or something like that. But for the life of me, I can’t find any kind of documentation on how to do something like that in Python.
[/quote]
If you have a file named “blah.py”, you would import it by doing:

import blah

You can then access the variables, functions and classes defined in blah.py like blah.someFunctionOrClass or so. To import them into the main namespace:

from blah import *

To import only a specific function/class/var:

from blah import someFunction
someFunction()

To give a different name for the module namespace:

import blah as somethingelse
somethingelse.someFunction()
# OR:
from blah import someFunction as coolFunction
coolFunction()

Absolutely. Using multiple python files for your app is a must if you don’t want your code to get very messy and thousands of lines of code. I have yet to see the project with just one file, so all packing tools work that way too.

Do you mean the Panda documentation? It assumes that people visit the Python documentation for Python-related issues.

No, I meant panda documentation pertaining to packing.

And thank you very much for that. That helps me out alot. I didn’t think it was the same because when I looked at the files that those lines in the examples referenced, they were encoded in binary.

Now new question; let’s say that the file I need is in a different directory.

The structure is this:

Main file:
root/main.py

File I need:

class.py
root/objects/class.py

Would this be legal or is it done in a different way:
import objects/class