Python being strange with blender

Ok so I have this problem, I have some scrips I wrote and they mostly run fine. But sometimes something strange happens with blender when I edit some scripts and save/run the game.

It’s like blender doesn’t read the changes to the scripts and reads an older version that’s been changed. It’s almost like its lagging behind the changes I made the the scripts. When I save and close blender and re-open the project the scripts are then read properly.

This doesn’t happen all the time but it seems the longer I have a file project open the more chance/worse it gets. I’ll give you an example of what I mean.

I write a script to print out a string and run it. It run’s fine. I then change the script to print out a different string and save it. It then prints out the string as if I never changed anything. I restart blender it then prints out the changed string properly.

Anyone had this problem?

Also I have a second problem I am kind just getting used to python 3 and so I’m still getting the hang of the changes made from python 2. I’m not sure if I have the syntax wrong or not but here is the problem.

I have 2 scripts one is full of useful functions. The other needs to use one of those functions to update it’s value. So I would normally import the script I want access to.
Then call the function I need. But I can’t seem to get anything but syntax errors when I try to call a functions that are in a separate file/class. Here is an example of the code I would use please help me find out what’s wrong with what I’m doing I’ve been trying for days.

from bge import logic
from bge import render
from bge import events as e
import weather

class player_stats:
    def __init__(self, cont):
        self.cont = cont
        self.own = cont.owner
        self.alive = 1
        
        self.body_temp = weather.temperature_function()

   def body_temperature_system(self):
       self.body_temp = weather.temperature_function()

   def main(self):
       self.body_temperature_system()
       print("self.body_temperature")

def main():
    cont = logic.getCurrentController()
    own = cont.owner
    
    if 'player_stats' not in own:
        own['player_stats'] = player_stats(cont)
    
    own['player_stats'].main()

main()

This script is connected to an object and will run always. As you can see I just want it to update the value from weather.temperature_function() then print the value.


def temperature_function():
    temperature = 20

    return temperature

This is the function I am trying to call.

Please if someone understands what I’m doing wrong, can you show me an example of how to call functions that are in separate files/class’s

Thanks for any help.

For your first question: python doesn’t automatically check if the file has changed and reimport it for you, you have to do it manually using imp.reload(module_name).

For the second question: dunno, it all depends on how your modules/scripts directories are set up and if you need to do relative imports or not – Py3k changed to non-relative imports by default so you have to specifically tell it where something is.

I just write my scripts in blender don’t they update automatically? or am I doing it wrong?