Saturday, December 14, 2013

Namespaces

     There's more about modules. This topic is pretty complicated, it's on namespaces. What are they?
     Well, let's say you were in this school. We'll just simply call it School A. There is one person in your class (Class A) named Gerry, but in another class (Class B), someone else is named Gerry. Each class is its own namespace, and the students are inside of it.
     So, if you were to say "Gerry got glasses" in Class A, everyone would assume you mean the Gerry in that class' namespace. You would have to say something like "The other Gerry" for the class to know it's not the Gerry it has. If the principal calls Gerry to come to her office over the loudspeaker, she would get everyone with that name. She'd have to be specific, like saying the last name (i.e. Gerry Vargas) or saying which class the Gerry she wants is from. To make things easier, she could just go to the classroom and tell Gerry in person. The principal has to be specific which namespace has the Gerry she wants.
     So, let's move on to importing namespaces. Let's say a class from another school (Class C) has to teach in one of School A's portables for a while. If someone from Class C is named Harry, but no one from School A is, and the principal calls for Harry, no one will come. She'd have to hook up the loudspeaker to the portables, and to do that, we have to import the namespace (Class C). We could simply do this:

from ClassC import Harry

    Or, if we want to make things faster, we could just do

from ClassC import *
   
     Ta-da! * will automatically import everything in the namespace we chose (ClassC), and now the principal can call anyone from that class whenever she wants. She can just do callToOffice(Harry) or call someone else. Something like that, at least.
     I know, my explanation is a little unclear. We should be able to give my examples a nice shine later on.

No comments:

Post a Comment