Why are we using the word ‘extant’ for documentation when it’s so often just a matter of adding ‘extension’ to the end of the name?
This was the main complaint we got when looking at the documentation for the Django API.
This is the first time we’ve seen a Python documentation that doesn’t mention Python 2 and 3, but that’s not to say that’s an uncommon complaint.
It’s not that we haven’t seen some Python docs that do mention Python 3.
What’s the big deal?
As the name suggests, Django is a Python 3 library, so it includes some Python 2/3 support, but it’s also a Python 2.7 library.
This means that Python 2 APIs are still supported by Django.
This is great news for developers, as it means that Django developers can write better Python 2 code.
In fact, the Django documentation says:For some Python programmers, the Python 2 API is the gold standard.
The documentation on Django’s website tells us that Python 3 is the next step for the future of the language.
This also means that many people are going to want to migrate to Python 3 at some point in the future.
But for others, Python 2 is still a viable way of working with Python 3 code.
This could be a good thing if you’re not an avid Python user, but for those who are, the documentation doesn’t give any hints on how to do so.
To see why this might be, consider the following code example:The Python 2 version of the function will be called, so the Python 3 version will be referenced.
But, we’ll also want to refer to the Python 1 version of this function as well.
The Django documentation explains that this is a syntax error, and that you can fix this by adding the word “extended” to the name of the version of Python you’re using.
This would be a great way to write code that works with Python 2, but unfortunately, there are two ways you can achieve this.
You can either use the Python version of that function as a base, or you can use the version that has the extension.
For the purposes of this article, we’re going to use the former approach.
If you’re unfamiliar with how to use Python syntax, you can read our Python 2 Reference Guide for more details.
So, let’s look at how we can fix the error.
To fix the syntax error in this code example, we need to add the keyword “extension” to both of the Python versions.
If we don’t do this, we get an error:It turns out that this error is not a syntax mistake.
It is, in fact, a coding error.
We’re going over the difference between syntax errors and coding errors, but first, a little explanation of how the Python syntax works.
This means that if you add an identifier to a Python statement, the value of that identifier is interpreted as a Python syntax error.
This error is caused by the way Python treats identifiers in identifiers.
The Python syntax for identifiers is a simple string with two dots and an uppercase letter.
In other words, it looks like this:The only way to represent an identifier in Python is to use an umlaut, or “unquoted” version of an identifier.
For example, the name foo.bar is an identifier with an u-like form.
In the following example, you’ll see a Python identifier with a name value of bar.
The u-style of this identifier is called the “unquote” version.
If the Python statement is a class definition, this would be called a “class declaration” and so the name would be foo.
However, a Python expression can be nested in an identifier, as we’ve shown.
In this example, foo.foo.bar would be the same identifier as foo.class.foo in the previous example.
If we try to run this code in Python 3, we would get an Error:We can fix it by adding a line of code to the bottom of the file:In Python 2 this code would look like this :In Python 3 this code looks like:In the example above, we’ve just replaced the identifier with the new name.
The code inside of the first line now looks like the following:The new line inside of this code has the new value of foo.unquote.
This makes the code much easier to read and understand.
We can use this same approach to fix the Python error in our code.
First, we add the new code inside the class definition:We need to fix this error by adding an identifier and using the umlauts as we did above.
We’ve added a class to our example, but we’ve also added an identifier called foo.
The class definition is a type that defines the base class of the class.
In our example above we’ve created a new type named