Hi, this is Julie Johnson with Firebox Training. Today in this Python training video, I’m going to show you how to install PyDev which is a nice little plug in you can use with Eclipse used to develop Python programs.
So I have right here is my Eclipse integrated development environment and the first thing we need to do to install PyDev is to go up to here to HELP and then Eclipse Marketplace. This just takes a moment and we’re going to perform a little quick search here in the find box and I’ll type in PyDev and then hit the search button. So you see here is the PyDev, Python IDE for eclipse and so we just hit the install button right here. We’ve got a couple choices here, we have PyDev for Eclipse and then we have extra Python Mylyn Integration. I really just want basic support for Python so I’ll just hit Python for Eclipse and then I’ll hit next. Okay here’s the license agreement; quickly read through all of this and then accepted license terms and then hit finish.
It’ll just take a minute or two it to install you know depending on how fast your network connection is. And once it’s finished installing you’re going to have to restart Eclipse. Now this popped up right here “do we trust these certificates” go ahead and check this and say okay. Now we need to restart Eclipse for the changes to take effect. Go ahead and say “yes”. Now I’m going to go to file new and you’ll see that it says here no applicable items. You may or may not have this kind of behavior, but in case you do all you need to do is go to the default perspective. Remember perspective is just the collection of windows that’s visible in your Eclipse environment it also controls what kind of projects you have access to. So it looks like I don’t have any perspectives opened. So I can just go to my window here and say OPEN PERSPECTIVE and then OTHER. For right now I’ll just say, oh here we go here is my PyDev Perspective, I can make that the opened one. Now here we have our PyDev Package Explorer. Now there are other windows to choose from, you’ll see here that I can go to window, Show View and we have all these other windows to choose from here. Okay so if i want to open up the console to see output from my programs I can do that.
So I’m going to just create a real quick Python program, just go up to FILE, New. I’ll create a PyDev project. I will just call this “First Python Project.” I’m going to click on this link here to configure the interpreter that I have and I just so happen to have Python 2.7 installed directly on my C drive so it looks like it’s already there, but if for some reason this is blank here you can always go to NEW and point to it.
Okay so i can just hit cancel here. I’m going to stick with all the defaults on this page here and just hit finish. So here it is my project and this will automatically show up in here, I can actually collapse this. Inside of my project I’d like to create a Python class. So I can right click on here and I’ll say NEW and I’ll say PyDev module. I’m going to call this package “com dot firebox training” and I’m going to call the name of my class, I’ll make this the Person class and I’ll hit finish. Now there are all these other templates in there too. You can play around with that too so you know what the templates contain. This is just a request for you to donate and I’m just going to X out of here for now.
Here we have our skeleton code. So I’m just going to create a new class that is called PERSON. It’s a subclass of object. I have a Constructor so you’ll see here that the IDE here automatically auto completes when I am creating functions in here. So if I want my Constructor to take a first name and last name, I can do that and I have default values of empty strings. Self simply refers to the object itself that’s getting instantiated, so SELF.firstname equals first name. Okay so this has to do the attributes of the object itself this is the local variable that’s getting pasted in right here.
Okay I will demonstrate on more thing here I am going to show you how to create a Magic String Function which returns a string representation of our person. So in here I’m going to say return self.firstname plus a literal space plus self.lastname. Now if I wanted to provide Getters and Setters I could, but I am keeping this really simple right now. So if I wanted to now test this, I could do that by instantiating a person object like this and even though it looks like there are three arguments, really I’m going to be passing in two pieces of information because this first argument refers to the object itself that’s being instantiated.
Now I’m going to now print out P and we’re going to now run this. We’ll do a Python Run and there we have it. Now what if we were going to import this class into another file? Well if we were to perform the import it would automatically invoke this code right here. So the way we can eliminate that problem is that we could have an IF STATEMENT in here. We can say, if double underscored name double underscore equals double underscore main double underscore, then we’re going to execute these two lines of code.
Okay said let’s use this in a separate file. I’m going to create yet another file. I am going ahead and put it that just for convenience sake in the same package. So I will just right-click in here and say new PyDev module. it’s in the com dot firebox training package and I’m just going to call this “person test.” I’m going to now import this. So there’s a couple ways we can import. I can say import “com dot firebox training dot person. If I do it like this, then I’m going to have to instantiated like this, “p equals” and fully qualified I would have to save “com dot firebox training dot person dot person.” That would be just too much typing. So there is another way that we can import this, we can say from this module we’re going to import the person class. So now I don’t have to fully qualify it. Let’s go ahead and print it out and let’s run it and you’ll see that it’s working just great.
Well if you got a lot out of this Python training video tutorial. Please visit our Python programming course outlines at http://www.fireboxtraining.com/python