Udemy also has some good tutorials for about $12-15usd on sale. https://udemy.com
2 Hints when learning Python
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.
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.
Indentation is critical for Python, pay attention to it. Indentation
also makes the code more readable.
Take small steps. Make sure you understand the current step before
continuing in to the next step.
Practice, practice, practice.
Don't be afraid to ask others questions. They are pretty
helpful.
Running Python works better in a Windows Terminal, not a cmd.exe
window. The Terminal is more configurable.
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
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.
Make sure to format your code as fixed width.
DO NOT post images of your code. People need to copy and paste the
code to run it, to try and help you.
Be specific about the problem, describe one problem at a time.
Describe the problem in detail, give the Python version you are
using, give a copy of the error message.
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.
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
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
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.
Debuggex. Test different types of regex like
Javascript, Python, PCRE (Perl). https://www.debuggex.com/
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/
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
Search for all non-printing characters: [\d128-\d255]
or [\x80-\xff]
Match all non-printable characters: [^ -~] (space
through tilde)
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.
+++ 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
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.
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.
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.
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/
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.
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/
Replit. ($) https://replit.com/ Replit is an AI-powered software
development & deployment platform for building, sharing, and
shipping software fast.