Screen Scraping with Beautiful Soup

Beautiful Soup is a Python library which is very handy for projects like screen-scraping.  Here’s a brief tutorial on how to scrape a list of the top 250 movies from IMBD.com and write them to a local text file: 1) Download Beautiful Soup Downloading Beautiful Soup is very easy. I’m currently using version 3 and […]

Python: Functions with Optional & Named Arguments

Python allows functions to have default values for arguments. These are used when the function is called without the argument. But where it gets really interesting is when you realize that in Python it’s also possible to name the arguments and call them in any order, which can be very useful. def shirt(styleID, size=’Medium’, color=’White’): […]

How To Reverse A String in Python

Unlike other languages such as Ruby, there is no built-in method to reverse a string in Python. Here are two possible ways to accomplish that:  1) The 'Long' Way This approach uses a for-loop with the join method to reverse a string: def rev(s): return ”.join([s[i] for i in range(len(s)-1,-1,-1)]) >>> print rev(“abcde”) edcba 2) […]

Learn Python the Hard Way

Over the last two years, I've spent considerable time learning several programming languages (PHP, C# and Ruby).  I started developing web applications with PHP, moved onto ASP.NET MVC using C# and then decided to experiment with Ruby on Rails.  I really loved the simplicity of Ruby and the 'magic' of Rails, but there was something […]