I am writing some programs for controlling my heating system. I have a class which is rather large and is used by several programs so I thought it would be a good idea to place that in a separate file and include it in the programs which need it. The problem I have now hit is that global variables need to be defined in each file that references them, which introduces the possibility of errors if I change one and forget another.

So having a single definition of the class is an improvement but having multiple definitions of global variables is a definitie disadvantage.

Is there a better way to do this? Are there any guidelines on writing modular code?

That is why Global Variables are a bad idea, best thing to do is change your code so you don't have Global Variables, if you mean Constant variables you could put them in a separate module module of there own and import them into what ever module needs them. Put variables in one place so you then get them and change them in only one place.

Show some of your code and you might get some advise on a better way of doing what you are doing.

The problem is that I have a debug log file for each main program, this is written to from both the main program and also the classes. I want a different log file for each main program, so that is the place to define it, but then classes.py errors because the log file is not defined. Is there a way to overcome this?

Wow! That looks brilliant. I had developed something to create a log file with line numbers, time date etc, but this goes way beyond that, plus it is all standard functionality. I now need to do a lot of reading, learning and testing Thanks for the adviseMick