Do Python Modules Really Have More Fun?
Since Python programming was first released to the world on the TI-84 Plus CE Python and the TI-Nspire™ CX II graphing calculators about a year ago, I think it’s time to dig a little deeper into the power of modular programming on these remarkable platforms, and discover why using modules can be more fun, or can certainly at least save you time.
Modules give us a powerful way to reuse common code
These custom “support” files are easily shared among my many Python programs and can be shared with others.
When developing a Python programming project, I find it helpful to divide the project into pieces and tackle them in smaller chunks. Python is designed for this approach from the ground up.
Modular programming is also useful if you or your students want to work in teams: Assign each member of the team a clearly defined task, have each develop a module, and then merge the modules into a single project.
The rest of this document explains the process of creating and using modules on the TI-84 Plus CE Python edition. Download the TI-Nspire™ CX II version for the same information specific to the TI-Nspire™ CX II graphing calculator.
The developers at TI have included some special files in the Python system. When you download and install the very cool Turtle module, you gain the ability to code in Turtle graphics! There are also additional TI_IMAGE and TI_DRAW modules as well as TI_PLOTLIB, TI_SYSTEM, TI_HUB and TI_ROVER, a BBC micro:bit module, and more to come.
For some introduction and practice with some of the TI modules, see the additional [+] Python Modules section of TI Codes for TI-84 Plus CE Python.
Note: There is also a Python Module library for the TI‑Nspire™ CX II graphing calculator.
|
Where are my files?
On the TI-84 Plus CE Python edition, all our .py files are stored as AppVars and have a special PY designation next to them when viewing them using [mem] > Memory Mgmt > AppVars. Some of my files seen here are in RAM and others are in Archive (*) to save memory. Only the files in RAM are available to use in the Python App. There may also be AppVars that are not PY files (even some that Python uses).
What’s a module?
I like to make a distinction between a Python program (or script) and a module. Both a program and a module are written using the same Python language but differ slightly in their purpose. A program is executable code that accomplishes a goal — it should do something. A module is also a Python file but is designed to be imported into a program (or another module), like the math and random modules. A module is designed to make common routines portable and can contain any Python code, functions and class definitions. Although it can be executed (“run”), it is not designed to actually do anything.
Some modules are provided in the Python App, and you can find them by entering either the Editor or the Shell and selecting <Fns…> Modul. Additional modules may be found in the <Add-On> sub menu in the Modul screen.
Import this!
The import statement makes the functions (and other code, like classes) that are stored in another file (the module) available to my program. There are three “flavors” of import statements:
- import math — all functions must be preceded by the module name: y = math.sin(x)
- import math as hoi — all functions must be preceded by the “alias” name you chose: y = hoi.sin(x)
- from math import * — all functions can be used without the module prefix: y = sin(x)
And, if you only intend to use one or two of the functions in a module, you can just state which one(s) to conserve memory:
- from math import sin, cos (no parentheses after the function names)
Writing a module
On the TI-84 Plus CE Python edition, I write a module the same way I write a program. The file is saved as you type. The module file may not do anything if you <Run> it, but running it can detect syntax errors in the code for you (but not runtime errors or programmer errors).
FIREWRKS (the center screen) is the program and COLOR120 is the imported module:
- FIREWRKS.py uses code from four modules to draw colorful random stars on the screen.
- COLOR120.py is a module I wrote that lets me use 120 bright colors of the rainbow to make random colors more vibrant. The module just contains three special lists: red[ ] (partially shown above), green[ ] and blue[ ].
Sharing our TI-84 Plus CE Python masterpieces
Python Modules give us a powerful way to reuse common code. These “support” files are easily shared among my many Python programs, and they can be shared with others too. If your TI-84 Plus CE Python program uses your custom modules, be sure to share the modules along with the main program, and be sure to provide ample documentation within the files (as #comments or as “”” comments “””). I’m looking forward to seeing your creations posted online. And a special thanks to the developers at Texas Instruments for creating additional powerful tools for a rich and engaging Python experience.
About the author: John is a retired teacher splitting time between sailing in New Jersey and mountain biking in Florida (did he get that backwards?), still getting kicks out of working with TI to provide feedback on new products and developing meaningful programming content for mathematics and science … and still having fun with all the graphing calculators and the accompanying toys.
Tagcloud
Archive
- 2024
-
2023
- January (3)
- February (3)
- March (5)
- April (3)
- May (3)
- June (3)
- July (2)
-
August (6)
- 5 Ways to Spruce Up Your Classroom for Back to School
- Day of the Dog: Which Dog Is Roundest?
- Women Who Code: A TI Intern’s Fascinating STEM Journey
- 6 Sensational TI Resources to Jump-Start Your School Year
- 3 Back-to-School Math Activities to Reenergize Your Students
- A New School Year — A New You(Tube)!
- September (2)
- October (3)
- November (2)
- 2022
-
2021
- January (2)
- February (3)
- March (5)
-
April (7)
- Top Tips for Tackling the SAT® with the TI-84 Plus CE
- Monday Night Calculus With Steve Kokoska and Tom Dick
- Which TI Calculator for the SAT® and Why?
- Top Tips From a Math Teacher for Taking the Online AP® Exam
- Celebrate National Robotics Week With Supervised Teardowns
- How To Use the TI-84 Plus Family of Graphing Calculators To Succeed on the ACT®
- AP® Statistics: 6 Math Functions You Must Know for the TI-84 Plus
- May (1)
- June (3)
- July (2)
- August (5)
- September (2)
-
October (4)
- Transformation Graphing — the Families of Functions Modular Video Series to the Rescue!
- Top 3 Halloween-Themed Classroom Activities
- In Honor of National Chemistry Week, 5 “Organic” Ways to Incorporate TI Technology Into Chemistry Class
- 5 Spook-tacular Ways to Bring the Halloween “Spirits” Into Your Classroom
- November (4)
- December (1)
-
2020
- January (2)
- February (1)
- March (3)
- April (1)
- May (2)
- July (1)
- August (2)
- September (3)
-
October (7)
- Tips for Teachers in the time of COVID-19
- Top 10 Features of TI-84 Plus for Taking the ACT®
- TI Codes Contest Winners Revealed
- Best of Chemistry Activities for the Fall Semester
- Best of Biology Activities for the Fall Semester
- Best of Physics Activities for the Fall Semester
- Best of Middle Grades Science Activities
- November (1)
- December (2)
- 2019
-
2018
- January (1)
- February (5)
- March (4)
- April (5)
- May (4)
- June (4)
- July (4)
- August (4)
- September (5)
-
October (9)
- Art in Chemistry
- Which Texas Instruments (TI) Calculator for the ACT® and Why?
- Meet TI Teacher of the Month: Jessica Kohout
- Innovation in Biology
- Learning With Your Students
- A first-of-its-kind STEM strategy charts path to help educators
- #NCTMregionals Hartford 2018 Recap
- The Math Behind “Going Viral”
- Real-World Applications of Chemistry
-
November (8)
- Testing Tips: Using Calculators on Class Assessments
- Girls in STEM: A Personal Perspective
- 5 Teachers You Should Be Following on Instagram Right Now
- Meet TI Teacher of the Month: Katie England
- End-of-Marking Period Feedback Is a Two-Way Street
- #NCTMregionals Kansas City 2018 Recap
- Slope: It Shouldn’t Just Be a Formula
- Hit a high note exploring the math behind music
- December (5)
- 2017
- 2016
- 2015