For a script that only runs once, say a setup script, you can use an Always Sensor without True level triggering (the buttons outlined in red in the image below). Doing so will unintuitively to the Always Sensor's name will only run once.
As for scripts where you only want a function to run once, but the rest constantly evaluated, I would highly recommend using The Python Controller in Module mode.
The way it works is you pass in the name of your script (must have a
.py), then the name of the function. So in the picture my script is named
script.py and the function I am calling is
The final way is to use a variable, or property.
cont = bge.logic.getCurrentController()
own = cont.owner
if 'init' not in own: # Will only run once, or when the var gets removed
own['init'] = True
Then if you need that code to run again use this line