Webucator blogs about online learning and training.

Webucator Blog

PHP converts dots to underscores in form submissions. Although this is documented and has apparently been true forever, I’ve never run into it before. The question came up in a comment on one of our YouTube videos explaining a change in how browsers deal with image submit buttons. Read the rest of this entry »

I had a bunch of Python files that I needed to convert in bulk to IPython Notebook files. I searched on converting .py to .ipynb, but was only able to find this Stack question, which provides an answer, which appears to be outdated. After digging through the nbformat module documentation for a solution to no avail, I wrote a little script for doing this. Read the rest of this entry »

IPython Notebook has a lot of useful shortcuts. You can access the list as a tooltip on the Help menu: Read the rest of this entry »

About two years ago, I started playing table tennis more seriously. I’m now in sort of a no-man’s land, in which I can beat most people who consider it a basement game, but can’t beat very many people who consider it a sport.

Because I’d rather write Python code than practice against my robot, I’ve created a model in Python to try to get an idea of what I should practice most to win more games. I’m unlikely to follow through on the practice, but I am likely to refine the model if people have ideas of how it could be made better. So, if there are any ping pong programmers out there, please feel free to make suggestions. Read the rest of this entry »

Given a list of objects in Python, what is the fastest way to find out the number of objects with a certain attribute value? I had already written a bunch of code using list comprehensions and then getting the length of the resulting lists, like this:

len([o for o in o_list if o.att == 'value'])

But then I googled to see if there was a better way and came across this stackoverflow question: Python Count Elements in a List of Objects with Matching Attributes.
The top answer suggests using sum() like this:

sum(o.att == "value" for o in o_list)

This works because True becomes 1 when converted to an integer. It looked good to me and I actually went ahead and rewrote a bunch of my code. Then I thought this would be good code to demonstrate the timeit module for the new Python course I’m writing. In doing so, I was surprised to find that the list comprehension method is significantly faster. Read the rest of this entry »

Just for fun, I wrote a Python script showing how the Collatz Conjecture works: Read the rest of this entry »

Yesterday, after I asked about a use case for finally in Python exception handling, I traded some emails with one of our very own .NET experts, Bruce Gordon. These days, Bruce mostly teaches SharePoint and SQL Server, but he gave me a great example that he used to use in his C# classes. With his help, I’ve come up with the following Python example, which I think provides a real-world use-case for finally: Read the rest of this entry »

There is a lot of documentation on the web that explains the flow of exception handling in Python. The official documentation does a good job of it. But I have yet to find a good example use case for the finally clause. If there are any Python experts out there who would be willing to show me a good use-case for finally, I’d appreciate it. I’ll explain my confusion: Read the rest of this entry »

Awhile ago, I traded emails with Christian Schramm about an article he had written called A Gentle Introduction to Generators in Python, which had been published on Tech.pro. Unfortunately, that site┬áhas since been taken down, at least temporarily: Read the rest of this entry »

In this short video, I show you how Python os.renames() method works: Read the rest of this entry »


© Webucator, Inc. All rights reserved. | Toll Free: 877-932-8228 | Outside the USA: 315-849-2724 | Fax: 315-849-2723