background preloader

Python

Facebook Twitter

The "Invent with Python" Blog — Nobody Wants to Learn How to Program. I frequently see a problem when people (especially techies) try to teach programming to someone (especially non-techies).

The "Invent with Python" Blog — Nobody Wants to Learn How to Program

Many programming tutorials begin with basic programming principles: variables, loops, data types. This is both an obvious way to teach programming and almost certainly a wrong way to teach programming. It’s wrong because nobody wants to learn how to program. If you are teaching a class of adults who are paying with their own money for an education, then this is an appropriate and direct way to teach programming. It’s their money. But for the casually interested or schoolchildren with several activities competing for their attention, programming concepts like variables and loops and data types aren’t interesting in themselves. Here are my five pieces of advice to people who want to teach programming or create programming tutorials: 1. But people can feel the limitations that these programs have. 2. 3. I began learning BASIC in the third grade. 3 useful Python scritps. I use Python more and more for simple scripting - it really excels at this!

3 useful Python scritps

The scripts I create with Python are very simple and easy to understand (unlike many Perl or shell scripts). Here are 3 useful Python scripts that I wrote for some time ago. Clean .pyc files I use Subversion for version control and I don't version the .pyc (Python bytecode) files. Import os , sys def pyc_clean ( dir ): findcmd = 'find %s -name "*.pyc" -print' % dir count = 0 for f in os . popen ( findcmd ) . readlines (): count += 1 print str ( f [: - 1 ]) os . remove ( str ( f [: - 1 ])) print "Removed %d .pyc files" % count if __name__ == "__main__" : pyc_clean ( ". " ) Searching for something specific with Python I wanted to find "cherrypy.request" in all the files, but not in the .svn directories (which are Subversion's directories). Thanks to Kate for pointing out the grep equivalent.

Grep -r "cherrpy.request" * | grep -v ".svn" Search and replace with Python. Projects for the Beginner - Python. Python Projects. As I write this, there are almost 3,000 projects in freshmeat's C category and almost 1,500 in the Perl category, but there are only about 400 projects in the Python category.

Python Projects

SourceForge has similar statistics. In this article, I hope to get more people to consider using Python in their next projects. My first programming languages were C and Perl. I found C very fast and powerful, but I had constant battles with ever finishing the projects I started in it. I mainly used Perl for one-liners and throw-away scripts. When I found what Python had to offer, I was amazed. There is a lot more to Python than what I can cover in this article, but I am going to show you a few Open Source projects that people have developed using Python, to give you a good idea of just what can be done with it. If you want to write programs with a Graphical User Interface, there are a few options. If you're interested in writing games, Pete Shinners's Pygame library is for you.