(Showmedo is undergoing major changes. To
report any problems viewing the videos please
email us and include
browser and OS specifics. Cheers - Kyran.)

Writing your first Python program may feel daunting - follow me here as I show you how to start a simple program inside PyDev (you could write this in any editor). I cover the useful features of PyDev including tooltips, auto-completion and using a 'Extract Method' refactoring tool (great for cleaning up your code!).

This simple script will read a list of numbers from a text file (as strings) and convert these to integers. We create a simple text file of numbers and process them using a Python loop, storing the converted integers in an array. This demonstrates simple looping and data processing techniques which will be useful if you need to process your own data.

The source code and data file (numbers.py, nbrs.txt) are available in the wiki so you can cut/paste them onto your own system.

To talk to your fellow Pythonistas you should join the ShowMeDo Learners Google Group.

Got any questions?

Video statistics:

Published: Sometime before 1st March 2007 (in other words - we don't remember!)

Thank-yous, questions and comments

If this video tutorial was helpful please take some time to say thank-you to the authors for their hard work. Feel free to ask questions.
Let the author know why their video tutorial was useful - what are
you learning about? Did the video tutorial save you time? Would you like to see more?

Ian, I've found your videos very helpful and thoughtful. Your efforts have saved me countless hours, so thanks. I'm new to Python, but very much enjoy it (background in c++ and object pascal, but some years ago. I'm now an optometrist and wish to create an interactive graphing app. Perhaps you'll take a question or two? Thanks again for the videos.Keep up the good work!

It's very nice and full featured; makes your job a bit easier. I especially like the fact that you can get support for many languages and dynamic languages inside the same environment, so you don't have to switch back and forth between different environments. Enjoyed the demo :- )

Ok, this was pretty helpful. Eclipse I got set up during previous episode--that was kind of a pain as I am of course a newbie and there were subtle changes in eclipse's appearance & behavior. Once one understands how to do simple things--like getting the da**#@ navigator window to open or rearranging windows--then those things become "intuitive"...But I tried to do those things, read the online docs, looked at Fabio's help and no joy. Then for some reason, whether due to something I did or just cosmic rays, navigator opened & I could rearrange, etc... I could not get pydev to immediately execute the "run" without having to specify 'python run' from the menu--each of the entire dozen or so times I did it while in the lesson. Then just now (5 or 10 min later) I clicked run and then pressed F11 and the thing instantly executed both times!! Is it deliberately playing with me? ;-)

Eclipse has been updated which is partly responsible for some difficulty in determining that I'm correctly following the lesson. But there are also benefits: now refactoring is smarter, it knows to move the def of readNumbers before it it is called, thus avoiding the error Ian had!

Hmm, terminology, I'll have to look into the exact definitions of function and method and I'll post again about this later.

Re. "nbrs = []", yes I should have said 'list' rather than 'array' - that's years of experience across many languages, I guess that was a bit of Java drifting in to my speech. You are right to question, it is important to get these terms right.

In reference to "line.strip()", I believe you said that strip was a function that operates on the string called "line". Did you mean method? Is there a meaningful distinction other than the notation ("function(object)" versus "object.method")? I've noticed that some functions seem to have been deprecated in favor of methods. Is there a move to view everything as a method, and therefore to use the words "function" and "method" interchangeably?

In reference to "nbrs = []", I believe you said that the statement created an array. Did you mean a list? Maybe it's a list that functions as a one dimensional array? I hate to be picky, but I tend to think by means of words (rather than thinking directly about things, as did, for example, G.K. Chesterton), so I have to get definitions exactly right or I get confused.

When you use the refactoring tool, Pydev can now automatically move the definition of the new function to the top of the module. Maybe they heard you. :-)

This is a very good "close to real worl programming" session in eclise+pydev.

Very sensible approach to include refactoring and unitesting in this early stage, rather than diving into the boring details of python syntax...

I like it.

But my eclipse(3.2.2)+python gave an error when I try refactoring... It is fixed the error. Also, it automatically puts the def at the beginning by default, which avoids the error you showed in the episode...

Educating the Open-source Community With Showmedo

Although as important as the software it supports, education
and documentation are relatively neglected in the Open-source
world. Coders love to code, and explaining how best to use or
improve the software tends to be deferred or even
sidelined.

At Showmedo we believe the community can play a vital role
here and also say thanks for the tools and software that make
our lives easier. If you have a piece of software you love or a
programming langugage you are enthusiastic about, why not make
a screencast showing others how to use it? All the stuff you
wish you'd been told, the tips, tricks, insights that would
have saved you time and frustration.

Screencasting is easier than you think, and we're happy to
help you. You can
emailus for
advice or just use some of the how-to screencasts on the site.
This
screencasting learning-pathis a
good place to start.

CLUB SHOWMEDO

Are you learning Python? To keep the site running clean and ad-free we've started Club ShowMeDo. The club will allow you access to some special videos we're making to pass on programming skills we consider important to the development and enjoyment of Free Open Source Software (FOSS).

The focus at the moment is on developing with the Python programming language, one of the backbones of the FOSS movement with a huge number of included and third-party libraries.

THANKS

Feedback

Showmedo's development is fairly rapid and bugs will inevitably creep in. If you have any problems please drop us a line using the contact address below. Likewise, any suggestions for improvements to the site are gratefully received.