Webucator blogs about online learning and training.

Webucator Blog

When working with Python properties, you might find yourself getting a “maximum recursion depth exceeded while calling a Python object” error. Here’s an example of code that will cause this error: Read the rest of this entry »

Python 3.5 was released this week. One of the new features is a new scandir() method in the os module. os.scandir() is a new speedier directory iterator. The cool thing is, you don’t have to update your code to benefit from scandir‘s speed because in Python 3.5, os.walk() uses scandir behind the scenes. According to python.org that makes os.walk() 7 to 20 times faster on Windows systems and 3 to 5 times faster on POSIX systems. My timeit tests on my Windows 10 (64-bit) didn’t show that great a speed benefit, but there is a definite improvement. Read the rest of this entry »

Here’s an quick function for creating a bi-directional dictionary in Python:

def bidict(d):
    d2 = d.copy()
    for k,v in d.items():
        if v in d2.keys():
            raise KeyError('Cannot create bidirectional dict. ' +
                           'Either d has a value that is the same as one of ' +
                           'its keys or multiple keys have the same value.')
        d2[v] = k
    return d2
hellos = {"Chinese" : "你好世界",
          "Dutch" : "Hello wereld",
          "English" : "Hello world",
          "French" : "Bonjour monde",
          "German" : "Hallo Welt",
          "Greek" : "γειά σου κόσμος",
          "Italian" : "Ciao mondo",
          "Japanese" : "こんにちは世界",
          "Korean" : "여보세요 세계",
          "Portuguese" : "Olá mundo",
          "Russian" : "Здравствулте мир",
          "Spanish" : "Hola mundo"}

The new dict will look like this: Read the rest of this entry »

In Jeff Knecht’s SQLite version of Sean Lahman’s Baseball Database, the debut field in the master table is stored in milliseconds from the epoch. Usually, you’ll want to convert that to something useful.

The results of the following query, which gets the five heaviest players of all time, don’t really tell us when the players started their careers: Read the rest of this entry »

In Python’s Regular Expression HOWTO, this tkinter-based regular expression tester is mentioned. Here’s what it looks like:
tkinter regular expression tester

I created a similar tool in IPython notebook for the Advanced Python course I’m currently writing. It was a fun project and I learned some cool new IPython notebook tricks, which I’ll share in this post. But first, an 11-second demo: Read the rest of this entry »

Here are the most important things a programmer should know about Unicode and UTF-8: Read the rest of this entry »

“There are only 10 types of people in the world: those who understand binary and those who don’t.”

To understand the joke, you must understand how binary numbers work. And once you understand how binary numbers work, it’s easy to understand how octal and hexadecimal numbers work as well. Read the rest of this entry »

In programming, it’s important to understand a little about how computer languages understand time. In particular, time is not the same across geography. The time in Moscow is different from the time in New York City. These differences wouldn’t cause too much of a problem if they were consistent, but they are not, in large part because Daylight Saving Time (DST) is practiced in some parts of the world, but not in others, and it goes into effect on different dates and times. Even that wouldn’t be too bad if there were some scientific way of determining where and when times were changed. But. alas, there is not. Read the rest of this entry »

As of Python 3.3, there are five different types of clocks in the time module, one of which is deprecated:

  1. time.clock() deprecated in 3.3
  2. time.monotonic()
  3. time.perf_counter()
  4. time.process_time()
  5. time.time()

I’ve been trying to figure out what different uses each of the clock types has. Read the rest of this entry »

I was surprised to find that date.strftime() is slower than converting the date to a string, splitting the string into a list, unpacking the list into year, month, and day strings and then concatenating those to format the date: 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