Webucator's Blog

|

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 »

|

Still using Python 2? It is time to upgrade.

Most Python programmers agree that Python 3, which has been available since 2008, is a big improvement over Python 2, but many (most?) Python developers are still using Python 2. The main reasons for this, according to a 2014 survey, are:

  1. They are relying on Python 2 libraries that have not been ported to Python 3.
  2. They have a large Python 2 code base, which would be time consuming and difficult to rewrite.
  3. They see no real advantage to switching.

But there are now clear signs that Python 2, which one developer argues we should start calling “Legacy Python”, is on it’s way out. Continue Reading »

|

How to Change the Home Directory for IPython Notebook

You used to be able to change the default (i.e., Home) directory in IPython Notebook on Windows by setting the c.NotebookApp.notebook_dir property in ipython_notebook_config.py, but that doesn’t appear to be working anymore. The workaround I found was to create a batch file and pin it to the Windows taskbar. Here’s how: Continue Reading »

|

Appending to Long Strings in Python

Be careful when repeatedly appending to a string in Python. Because strings are immutable, each time you change one, a new object is created. The code below is very intuitive:

r=1000000

s = ''
for i in range(r):
    s += str(i)

But it doesn’t perform too well.

A better approach is to create and append to a list and then convert it to a string using ''.join(l), like this: Continue Reading »