Traffic Simulation - not sure where to put behavior code

Hi everyone! I followed this tutorial:

up to a certain point. It teaches you how to make those nice lowpoly buildings and some other stuff. When he proceeded to demonstrate how to make the city block by block, I figured that I would rather automate that with code.

That was simple, here’s the code I used
http://pastie.org/9595574#

And a screenshot of the result (what’s up with the textures?)
http://imgur.com/R0jZpBU

Now I want to simulate the traffic in BGE! I have the behavior code roughly sketched out here (sorry for the mostly italian comments)
http://pastie.org/9595572#9

Problem is, I have no idea where to put it, what to interface it with. Each piece of road that is created with the script above should end up:

  • having references to 2 “Way” objects(one for each lane)
  • having references the adjacent pieces of road and their Way objects
  • spawning cars every once in a while, and moving them around

How would I do that?
I could create references between ways and pieces of road directly within makecity.py, the first script, but where do I store them so that I can use them in BGE?
In general, I really don’t know where to look to implement persistence in Blender.

Sorry if the question may seem basic(I did skim the FAQs), and thanks.