Skip to content
Coffing Data Warehousing Software

Understanding Advanced Python Part 5

This post is the fifth part of a series on Advanced Python. In this series, we’ll take what we learned in our Understanding Python Basic series (Part One of that series found here) and expand on it to understand the more challenging parts of Python. In Part 5, you’ll be learning about Reading and Writing files in Python. 

If you want to use the Nexus as your Python editor, then you will find instructions at the end of the blog on how to set this up!

Tera Tom here! Welcome to Part 5 of our lesson on Advanced Python! Before I begin explaining Reading and Writing files in Python, let’s make sure you have everything you need to follow along with this lesson. If you have a Python editor you want to use then you are all ready to go, but if you want an easy way to try these examples and more then go to www.CoffingDW.com and download the Nexus.  Once you have it installed just look at the picture below and see where the Python editor of Nexus exists.  If you want to install Python so you can practice with Nexus then go to the last page of this blog for detailed instructions.

The segment will be split into TWO parts. Today’s part will be focusing on the core concepts of Reading and Writing files in Python before we see an example of this by using a Teradata System. On Wednesday, we’ll explore how this works using an SQL database and explore some more advanced options when it comes to Reading and Writing files in Python programming.

The Six Access Modes of Python

Access modes in Python control the type of operations possible in an opened file and refer to how you are using the file. These modes also define the location of the File Handle in the file.  The file handle is just like a cursor. It defines where the data has to be read or written in the file.

Writing to a File

Below is how you create a file and write to it.  We have written three rows.

Reading from a File

Below is how you open a file.  We then wrote two rows to the file.  We then closed the file. We then opened the file and checked for the name of the file.  We then discovered the mode of the file. We read the file and then printed the contents.

Removing a File

Below is how you close and remove the file.      

Python Classes (1 of 3)

The next three slides will show how to create a class.

Python Classes (2 of 3)

The next slide will continue to show how to create a class.  

 Python Classes (3 of 3)

The next slide will continue to show how to create a class.

Inheritance (1 of 2)

When you inherit from another class, you get all of the variables, methods, and functions you are inheriting from the other class.

Inheritance (2 of 2)  

When you inherit from another class, you get all of the variables, methods, and functions you are inheriting from the other class.

Method Overloading

Below is an example of method overloading.

Inserting Rows into a Teradata Table  

Use the below steps to connect to a Teradata database and insert two rows into the employee_table.  

Connecting to a Teradata System and Selecting from a Table

Use the below steps to connect to a Teradata database.  We also ran a query that brought back rows from the employee_table.

Connecting to Teradata and Calling a Stored Procedure

Use the below steps to connect to a Teradata database.  We also called a stored procedure named Python_Proc. Turn the page to see the actual stored procedure we first created on Teradata.

The Stored Procedure We Created on Teradata  

On the previous page, we showed an example of calling a stored procedure in Python.  Below is the exact stored procedure we created first.

How to Install and Setup Python on your Nexus

  1. Download the latest version of Nexus from our website.  https://www.coffingdw.com/nexus-trial/
  2. Once installed download Python for Windows.  https://www.python.org/downloads/windows/

Your version number can vary, but you will want to download the Windows installers. So for Python for Windows 3.7.3 located here (https://www.python.org/downloads/release/python-373/) you will select one of these highlighted links:

Note:  Nexus comes in three versions:  Nexus 64-bit, Nexus 32-bit, and Nexus WOW-64 (For 64-bit machines with 32-bit Microsoft Office installed).X86-64 can be used for the 64-bit or Wow64 version of Nexus and x86 can be used only on the 32-bit version of Nexus.

When installing, if you have the option, select “Add Python to PATH”.


If you are using an older version of Python and do not have this option, then you will need to add the path to your python executable to your PATH environment variable. Be careful when editing this variable as it can affect many Windows functionality issues. If you don’t feel comfortable about this then consult with your desktop support.

Python 3.7.3 was installed in the following directory on our PC.

C:\Users\Todd\AppData\Local\Programs\Python\Python37

You can view your Python directory by opening File Explorer and pasting in the following path:

%LocalAppData%\Programs\Python

Once you have the path to the python.exe executable then add it to your Environment PATH variable by following the direction in this link:

https://www.computerhope.com/issues/ch000549.htm

And that is how you install Python into the Nexus Query Chameleon! 

Ready for more Python training? Make sure to check back on Wednesday for further lessons on Advanced Python! Or, if you’d prefer Tera-Tom to come teach at your organization, contact our team for booking information.