Python

Updated 2026.05.16.d

This file has tools oriented to Windows users.

Made with the most excellent and free Pandoc document converter, by converting Markdown to HTML. And Pandoc puts in the Table of Contents too!

This web page not a tutorial, these are just notes on Python I have collected.

Neocities has free web pages with no ads, but only supports HTML, CSS and Javascript.

1 Python tutorials I like

  1. Freecodecamp. https://freecodecamp.org
  2. Indently tutorials on Youtube. Site: https://www.youtube.com/@Indently Python Tutorial from 2023: https://www.youtube.com/watch?v=bnSYeYFRCaA&list=PL4KX3oEgJcffJTxggH5LviQeMHiNagq3y The only issue here is you should use f-strings now, not %s for variables inside strings.
  3. Udemy also has some good tutorials for about $12-15usd on sale. https://udemy.com

2 Hints when learning Python

  1. Be patient. If you don't understand something, reread the instructions or view that tutorial section again. If you still don't understand, ask on the main forum.
  2. Use a plain text editor to enter code. Source code files are plain text. MS Word is not a plain text editor and people often misuse it. In MS Word, typing in the extension of a file does not determine the file's contents, the way you save it does. See the Text Editors section in the Table of Contents on this page.
  3. Indentation is critical for Python, pay attention to it. Indentation also makes the code more readable.
  4. Take small steps. Make sure you understand the current step before continuing in to the next step.
  5. Practice, practice, practice.
  6. Don't be afraid to ask others questions. They are pretty helpful.
  7. Running Python works better in a Windows Terminal, not a cmd.exe window. The Terminal is more configurable.
  8. pygame does not work with Python 3.14+, it was replaced with python-ce a drop-in replacement. But AI will sometimes tell you to use pygame which is incorrect.

3 What is a class?

Sometimes people struggle to understand a class. A class is just a box with many other variable types in it. A class can have "properties" or "attributes" (variables) and functions.

Think of variables as objects that can hold one value, like an integer, or hold many values, like a list. A class defines another custom object which is more complex. A class is a blueprint for a variable/object with integers, strings, lists, dictionaries, or more and it can have its own functions called methods. The variable portion of a class object are called properties or attributes, it depends which language you talk about.

A "class object" is a variable of that class. So in a video game we can make a player character class with these properties: Charactername, strength, intelligence, dexterity, speed, and an image for what they look like. And every character uses the same class but with different values for the variables/properties inside that class.

3.1 Example class

I use this class to pass options to every function I use. It can hold a lot of data, including large lists and large dictionaries.

import os   
import time
#####################################################
# Classes
# Option variables go here.
# Ways to access class members/properties: print(options.debug)
#    print(vars(options)['debug'])
#    print(getattr(options,'debug'))
class clsOptions: # This is the class blueprint.
    r'''
    (write what this class is for)
    '''
    def __init__(self):
        r'''Define the class variables/attributes we need to use with initial values.'''
        # Program options
        self.debug = False # From --debug
        self.debuglist = [] # List of models to debug/break on.
        self.optlimitread = 0 # 0 = no limit on reading records.
        self.optoverwrite = False # True to overwrite output files, for testing.
        self.optcolorchg = 0 # From --colorchg:N
        self.starttime = 0 # Used to time how long the program takes to run.

    def __repr__(self):
        r'''Usage: in debugger to show the value of all class attributes like this: p options
        This reduces typing quite a bit.
        '''
        procname = "__repr__:" # Procedure name.
        s = f"{procname} This holds command line options.\n"
        s = s + f"debug={self.debug}\n"
        s = s + f"debuglist={self.debuglist}\n"
        s = s + f"optlimitread={self.optlimitread}\n"
        s = s + f"optcolorchg={self.optcolorchg}\n"
        s = s + f"optoverwrite={self.optoverwrite}\n"
        s = s + f"starttime={self.starttime}\n"
        
        return s
        
# Here we make the instance of a class, the actual variable we use.    
options = clsOptions() # Make the class variable/instance.
options.starttime = time.time() # Set a class property

4 Programming and AI

Why is AI often bad to use with programming? AI can be used to get snippets of code to do a task but it is generally not great at writing whole programs.

I found this out the hard way. I was asking AI how to do stuff in Python, and didn't mention the Python version. AI was giving me code from 13 years ago that didn't work in modern python. You have to be really specific with your questions. Once I included the Python version in my questions all the code worked.

And I asked AI to write a program (a screen saver) using pygame but it never knew pygame was deprecated and replaced with pygame-ce. So my program didn't work in Python 3.14 until I used pygame-ce (community edition). Regular Pygame wasn't updated for the newer version of Python.

AI seems fine to suggest snippets of code for a task I want to do but it is not good at designing the overall program, especially using proper security for an online web program.

Just find Python tutorials on Youtube. I like the free Indently tutorials. Or use https://freecodecamp.org/. They have a Python tutorial on YT as well.

5 Python forums

5.1 When posting questions to a forum

  1. Describe the problem briefly in your subject. DO NOT put "Help me", "Problem" in the subject or anything that does not describe your problem. Writing up a forum post takes practice. You will get more help with a useful subject.
  2. Make sure to format your code as fixed width.
  3. DO NOT post images of your code. People need to copy and paste the code to run it, to try and help you.
  4. Be specific about the problem, describe one problem at a time.
  5. Describe the problem in detail, give the Python version you are using, give a copy of the error message.
  6. Using AI produced code or posts in the forums is discouraged. AI is sometimes wrong but won't tell you that. Building AI prompts takes thoroughness and it can still be wrong.

5.2 The forums

  1. Main forum. It's very active and helpful. https://discuss.python.org

6 Python tools

Tools to use during development. Most online tools require a login if you want to save your work.

6.1 Text editors, free

  1. Notepad++. Plenty of features and addins. https://notepad-plus-plus.org/
  2. PSPad. This editor sometimes burps strange characters in your code but it's rare. If it does this while text is selected the text will be replaced with garbage. https://pspad.com
  3. Ted Notepad. Tiny editor. It's for a Windows cmd.exe window or Windows Terminal. It's a small fast editor, I use it for .bat files mainly. https://jsimlo.sk/notepad/

6.2 Misc

  1. 7-zip. This is my utility for making .zip backup files via command line. https://www.7-zip.org/

6.3 Test Regex

Regular expressions in Python are a powerful tool for finding textual data.

  1. Debuggex. Test different types of regex like Javascript, Python, PCRE (Perl). https://www.debuggex.com/
  2. Regex Kit. Test various types of regex like PCRE, Javascript, Pythan, etc. https://regexkit.com/regex-tester
  3. Regex 101. This has a regex explainer. Enter your regex and test data to test it. Sign in to save your test cases. Has many flavors of regex to test like: PCRE2 (PHP), Javascript, Python, Golang, Java, .NET 7.0 (C#), Rust, and more. Sign in with Google or Github accounts. https://regex101.com/
  4. Regexr. Enter your regex and multipule lines of test data. This will highlight the data to show matches. Sign in to save your tests. Use your Github or Google account to sign in. https://regexr.com
  5. Regexpal. Has login. https://www.regexpal.com/
  6. Regextester. Test different flavors of regular expressions like PCRE. Has login account. Text won't fit to browser window. https://www.regextester.com/ This might be the same: https://regextester.github.io/
  7. Search for more: https://search.brave.com/search?q=free+account+test+regular+expression&source=web

6.4 Regex quickref sites

For a quick reference to regex. Some of these sites have tutorials.

  1. PCRE Regex Assertions docs. https://www.php.net/manual/en/regexp.reference.assertions.php
  2. RexEgg. Learn regular expressions. https://www.rexegg.com/regex-quickstart.html

6.4.1 Handy regex

  1. Search for all non-printing characters: [\d128-\d255] or [\x80-\xff]
  2. Match all non-printable characters: [^ -~] (space through tilde)
  3. Match all printable characters: [ -~]

6.5 Run test code online

6.5.1 No login needed

These sites may or may not save your code that you type in. Always have a backup of your code. But they can be used to test small snippets of code or concepts.

  1. +++ Attempt this online. This is really cool! Supports many languages like: Python, Ada, AWK, BASH, C, C++, Java, Javascript (node.js), Lua, Perl, PHP, PowerShell, many more!. No login or account needed. https://ato.pxeger.com/about
  2. Online Python. No account needed for login. https://www.online-python.com/
  3. PyNative Python Compiler. No account needed. https://pynative.com/online-python-code-editor-to-execute-python-code/

6.5.2 Login needed?

  1. Anaconda. https://anaconda.com You can use Anaconda to develop and deploy Python solutions, manage packages, and create environments for data science and machine learning projects. Store and share notebooks. This sounds similar to Jupyter. Write and debug code with their AI.
  2. Google Colab. Login via your free Google account. This works just like Jupyter labs. https://colab.research.google.com/
  3. Jupyter Labs. https://jupyter.org/ You can run this in your browser or install it locally. Data is stored in your browser so if you use another browser or PC your data will not be there.
  4. OneCompiler. https://onecompiler.com/python Uses Google account but login only needed if you want to save your code. This supports many languages like Bash, Basic, Pascal, Python, Java, Javascript, C, C#, C++, NodeJS, Groovy, Haskell, PHP, Typescript, and more.
  5. Pyscript. Run Python in a web browser. You can use this on your site as well. You probably need full shell access to make this work on your site though. https://pyscript.net/
  6. PythonAnywhere ($) by Anaconda. This costs money. https://www.pythonanywhere.com/ This is used to host websites. They have quick installers for Django, web2py, Flask, and Bottle frameworks.
  7. PythonHow Python Shell. https://pythonhow.com/python-shell Write program and run it, or use online Python shell.
  8. Python dot org shell. This is the Python prompt shell to run only single commands. There is no editor here. No login needed. https://www.python.org/shell/
  9. Replit. ($) https://replit.com/ Replit is an AI-powered software development & deployment platform for building, sharing, and shipping software fast.
  10. A search for more. https://www.google.com/search?q=run+Python+online+free

7 Python code

7.1 Get version of python

Via command line: python --version

In code:

import sys
print(sys.version)
# Output like: '3.11.9 (tags/v3.11.9:de54cf5, Apr 2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)]'

# More details
speedtestname = "Module name"
print(f"First: {sys.version_info}")
if (sys.version_info > (sys.version_info.major, sys.version_info.minor, 0)):
    # sys.exit(f"ERROR: This module {speedtestname} only supports Python 2.4 - 3.7.")
    pass

# Find shorter version like: 3.11.9
import platform
print(f"Second: {platform.python_version()}") # Prints '3.11.9'
t = platform.python_version_tuple() # If you want a tuple
print(f"Tuple: {t}") # prints '('3', '11, '9')'