In addition to PHP, the other language I have been trying to learn is Python. Primarily, I have been trying to select a new computer language because I think I have outgrown VBA. I looked at Perl, but there seems to be a ton of help for Python, plus, since SPSS can be controlled within the language, I decided to give it a shot. For the most part, I want use it to get data off of the web and be able to write it into a database or SPSS. In the end, I think I might be able to get dynamic data, model it in SPSS and write reports (maybe into Word?). I am pretty excited for the prospects, but I have a lot to learn.
When I learned VBA, I got used to the editor environment. When I moved to Python, I was trying to find something similar. In Python terms, I was looking for an IDE. You don’t need one of course, as you can just type in commands one by one in the Interactive shell, but that is not exactly the best way to go. I tried PythonWin, but it just wasn’t cutting it.
Up comes Eclipse. I have heard a lot of people talk about it, or reference it, but I couldn’t quite figure out what I was supposed to do. Again, I am not a computer scientist; hobby programmer at best. Everything I searched for appeared to be geared towards those who could invent a whole new language, as such, I felt like it wasnt for me. However, after some searching and patience, I think I figured it out, and just after playing around for an hour so, I am excited for the possibilities. As such, I am going to outline the basic way I setup the environment and highlight some of the things that stand out to me.
- Download Eclipse here http://www.eclipse.org/downloads/. I first Downloaded Eclipse Classic. My first stumbling block was “which one to select?” While I think that was a fine choice, I realized that I probably would want to try my hand at PHP as well. I subsequently downloaded the PHP developer tool and added PyDev again as described below. Now I can write PHP and Python code from the same tool!
- I unzipped the folder and saved a shortcut to my desktop.
- I do not believe that Eclipse natively supports python, but you can install external modules that expand its capability. To do this, go to Help > install new software.
- At this screen, you will add a site. The Python functionality sits in a module called PyDev. Point to this http://www.fabioz.com/pydev/updates
- Pydev will be a selection. Select it, accept terms, and install it. You have to restart Eclipse, but after that, Voila, good to go.
- You need to change the Interpreter. Go to Window > Preferences, select PyDev, Interpreter – Python, new Interpreter, and point to the python.exe file in your install folder. On Windows, it is probably C:\\Python2X. Select the file, and name it. NOTE: If you Google Configure Eclipse Python or Setup Eclipse Python, you should see some help.
- Finally, to create a new Python script as you would in PythonWin or any other IDE, go to New – select PyDev Project. Give it a name and select OK (more about projects in a second). It will put it in the project tree on the left. Right click the project, select new Pydev module. From this point, you can start coding in Python!
Now, as to why I like Eclipse. First, it dynamically gives you updates on errors, before you run your code. Second, it also tells you if a variable or imported module is not used, or even available in your Python environment. This is extremely helpful, especially when you are trying to modify code that you found on the Internet.
Also, and this wasn’t obvious to me at first, but I LOVE the idea of projects. If I am testing code, learn new tricks, see code examples that may be applicable for a task, I save the scripts in the applicable project. For example, I want to collect alot of data for professional sports, so I created a project for each sport of interest. Essentially, it allows me to organize my work. I can even insert text files as a reminder of things I want to do, need to learn or have learned. Now, it goes without saying that this probably isn’t the proper use, but hey, it works for me.
Either way, I think I am really going to like developing in Eclipse. My errors are obvious (I had a hard time deciphering errors in PythonWin) so fixing my code will be easier. There are “tooltips” that help you complete code, which is something I was used to when writing VBA. Finally, I love that I can keep all of my scripts organized together. I will keep you posted if my opinion changes, but as of now, I would GREATLY recommend Eclipse for someone who is trying to learn a programming language.