This post is the eight 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 8, Tom will be revealing some fantastic tips and tricks for 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 7 of our lesson on Advanced Python! Before we jump into handling JSON data, 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.
Tips – Printing the File Path of Imported Modules
You can set breakpoints in your Python script with the help of the <pdb> module. You can actually specify <pdb.set_trace()> Anywhere in your script and set a breakpoint there. Wow, how nice is that! Tips – Setup File Sharing
Python allows running an HTTP server which you can use to share files from the server root directory. Below are the commands to start the server for both Python 2 and Python 3. Tips – Inspecting an Object in Python
You can inspect objects in Python by calling the dir() method.
Tips – Detecting the Python Version
Sometimes you may not want to execute a program if the Python engine currently running is not the supported version. Use the technique below to determine if the correct version is there or else you can exit. The first example prints the currently used Python version in a readable format.
Enumeration finds an index inside a loop, but the below approach can be used to create enum definitions.
Tips –Unpack Function Arguments via the Splat Operator
Python allows you to use the splat operator (asterisk *) to unpack arguments lists.
Tips – Resetting the Recursion Limit of 1000
Python restricts a recursion limit to the value of 1000. We can reset its value by using sys.setrecursionlimit.
Tips – How to Check the Memory Usage of An Object
The Python sys.getsizeof()) method returns the memory usage in bytes.
The Python sys.getsizeof()) method returns the memory usage in bytes. Notice that in our second example, we used __Slots__ to reduce the size of memory usage. Reducing slots can be a very valuable technique.
How to Install and Setup Python on your Nexus
- Download the latest version of Nexus from our website. https://www.coffingdw.com/nexus-trial/
- 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.
You can view your Python directory by opening File Explorer and pasting in the following path:
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:
And that is how you install Python into the Nexus Query Chameleon!