EX 45: Breaking up the code

As one of the requirements for Ex 45 is to have more than one file and use import, I have decided that due to the complexity of getting the code for moving from room to room in the game working that I should get the movement code working in one file first and then split it up into two files (or more). If I tried to make it work with two files from the start I think that would add un-necessary headache to what is already proving to be a real slugfest for me.

My question is, is there anything I need to worry about in terms of dependencies and operating order when I choose which class(es) I choose to move to the file that will be imported? Anything I should be on the alert for when I write my code now that would make it easier to split up later?

I’m guessing the answer is there’s probably minimal concern on this issue since import is going to happen before you get to the first class in the main .py file. But I thought I should ask anyways…

Really it should be a simple process of changing code like:

x = RoomClass()
y = BarClass()


import rooms
import bars

x = rooms.RoomClass()
y = bars.BarClass()

That’s it really.

1 Like
A free service run by Zed A. Shaw for learncodethehardway.org.