Webucator's Blog

|

Simple Python Script for Extracting Text from an SRT File

Watching movies or TV shows in a foreign language is great for learning that language, but it can be challenging. Quick speech, slang, and background noise can all make understanding more challenging. I find it helpful to have subtitles that match the speech, but foreign-language films/shows don’t always have subtitles. Fortunately, you can often find subtitle files (with a .srt extension) at opensubtitles.org. Unfortunately, those files aren’t easy to read, because they are marked up with timestamps and include every sound made (e.g., mobile phone ringing). Continue Reading »

|

Python Project for Job Application

You have an opening for a Python developer in your company. Your company is awesome, so you expect to get a lot of applications. You only want to interview developers who have some experience writing object-oriented Python code. You don’t need to test the breadth of their immediate knowledge as much as their ability to get a project done using all the resources available to them.

Here’s an idea for a project you can give the candidates to demonstrate their proficiency with Python. Continue Reading »

|

When to use Static Methods in Python? Never

The short answer is in the title. Never use static methods in Python.

The initial intention of this post was to provide a simple and concrete use case for a static method in Python. I started with this 7-year conversation about static methods on StackOverflow, which seemed promising. But it doesn’t contain a single practical use case. And I think I know why. There are none.

Creating a static method is straightforward enough, but as Nathan Tregillus sort of asks in this post, the real question is why would you ever want to?

In answer to a similar question about when to use static methods in Java, Associate Prof not-just-yeti wrote this short-and-sweet explanation: Continue Reading »

|

Checking your Sitemap for Broken Links with Python

We are about to launch a new website and, in doing so, we have restructured our URLs and used 301 redirects to point the old URL to the new URL. To make sure that we caught all the changes, we compiled a list of URLs on our old site using our sitemap and the Landing Page report from Google Analytics. We then used the Python’s request library to check all the URLs.

Using BeautifulSoup, you can easily check your own sitemap to make sure you don’t have any links pointing to missing pages. The code below shows how to do this using the NASA sitemap.
Continue Reading »

|

Python 3 surpasses Python 2 on Stack Overflow – April, 2016

Python 3 came out in 2008. That’s eight whole years ago. This past month, April 2016, is the first month that there have been more Python 3-related questions on Stack Overflow than Python 2-related questions. It has taken a long time, but Python 3 finally seems to be getting as much usage as Python 2. It’ll be interesting to see if this is a tipping point and usage of Python 2 begins to plummet. Here’s the latest chart:
Continue Reading »