-
-
Save approaching236/e2a2ad49582370293a27d7a3b90e7a68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Made with <3 by Vincent Grato, vgrato@gmail.com | |
# comments start with a hash symbol (the pound sign) | |
# comments are not cude, they are a way to address the programmer | |
''' | |
you can create multiline comments with something called a Docstring, here it's the three quotes above and a number of lines below | |
Programming is often more than one language | |
if I use `these special forward quotes`, I'm doing something in code | |
if I use `$ command` those quotes with a $ at the front, I'm coding in bash | |
if I use `>>> something_or_other`, with the >>> at the front, I'm coding in python | |
!!! if you aren't seeing this file in multiple colors, go get a text editor like sublime or atom or vs code to work in. Syntax highlighting is super important !!! | |
!! less important, but still nice: rainbow parens, rainbow csv, line numbers !! | |
python install | |
============== | |
ideally already! | |
in terminal try: | |
`python3` | |
if you get something like: | |
``` | |
Python 3.10.6 (main, Aug 10 2022, 11:40:04) [GCC 11.3.0] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> | |
``` | |
you good | |
python2 is still floating around. it's enough different to be not guaranteed compatable, but sometimes you can't tell. Try to use 3 these days. | |
if nothing is installed. Anaconda is a good way to get a working python install | |
Running Stuff | |
============= | |
you can run the file in terminal by `cd`ing into the directory with this file and running: | |
`$ python3 grammin.py` | |
I do normally run my programs from the terminal as a command with arguments | |
there is also something called the Read Eval Print Loop that I use as an exploration tool | |
from bash | |
''' | |
# Variables and data types | |
# variables are named containers of data that you can read and write to | |
# there are tons of built in data types and you can import various libraries and of course build whatever custom types you'd need | |
# some common ones: | |
variable_names_are_in_snake_case = True | |
flag = False | |
undefined_maybe_nil_wu_unask__ = None | |
an_integer = 12 | |
a_float = 3.14 | |
hello_string = "this is a string of text, obligatory Hello World!" | |
worth_noting = 3.14 # like, the number of length 3.14 | |
is_not_the_same_as = '3.14' # cuz this one's a string, which has a length of 4 symbols | |
list_literal = [1, 'abc', 0] | |
read_only_file_pointer = open('some_file.txt', 'r') | |
# data types are a complex topic, some languages really care about them, others seem to want to pretend they don't exist | |
# I think python strikes a happy middle ground, if maybe a little looser than I'd prefer in terms of assuring you're getting what you expect, but this is kind of a nuanced topic | |
# bottom line, most variables stay one type in the run of a program. There are subtle incompatabilities between data types that are often ambiguous or absurd | |
# Things like: | |
# if I have a list ab = [1, 2, 3] | |
# does it make more sense that `ab + 3` would return [1, 2, 3, 3] appending a three, [1, 2, 3] ignoring cuz three is already a member, or [4, 5, 6], incrementing each element by 3? | |
# if you tried to run that and got no such flie some_file.txt: `touch some_file.txt` in terminal | |
# there is another type of variable called a global that is GENERALLY_FROWNED_UPON_BUT_USEFUL_IN_CERTAIN_CONTEXTS | |
GLOBAL = '/some/config/file/or/binary/or/timezone' | |
BIG_IN_MEMORY_INDEX = {} | |
# {} curly braces define a dictionary, also called a hash, map, hashmap or dict | |
''' | |
an example: | |
>>> ab = {} | |
>>> ab[1] = 'apple' | |
>>> ab[0] = 'orange' | |
>>> ab['foo'] = 'bar' | |
>>> ab | |
{1: 'apple', 0: 'orange', 'foo': 'bar'} | |
>>> ab[1] | |
'apple' | |
''' | |
# Quick note on sources for learning | |
# in the python3 repl, look at the output for: | |
# >>> help(range) | |
# This is python's built in documentation system, I reach for it before the internet often | |
# most of the websites out there that aren't straight docs or stack overflow are hot garbage | |
# | |
# really good docs (worth breezing through but don't get bogged down in): | |
# https://docs.python.org/3/library/intro.html | |
# https://docs.python.org/3/library/functions.html | |
# https://docs.python.org/3/library/constants.html | |
# https://docs.python.org/3/library/stdtypes.html | |
# https://docs.python.org/3/library/exceptions.html | |
# Trey Hunner's stuff is a genuine echo of what was beautiful about the old web | |
# check out the builtins: | |
# range can be used to generate a list | |
one_to_ten = range(0, 10) | |
# print(12345, [one_to_ten, True]) | |
# the function print outputs values to the screen, even if they're compound data structures like a list of lists | |
# There are a lot of good libraries you can import that come standard with python | |
import argparse # bash is the one true programming language | |
import itertools # fucking cool | |
import functools # also cool, but in a harder to use way | |
import multiprocessing # and then I got bugs. I added concurrency, way faster. But like, | |
import time # a delightfully philisophical nightmare of a read: falsehoods programmers believe about time | |
import math # mega calculator | |
import csv # the one true data type. Effectively a spreadsheet where each row has the same type in a given column. Really important to be able to read and write these as a programmer | |
import numpy as np # mega mega calculator | |
import sympy # mega mega calculator, now complete with Math, the programming language | |
import mingus # music theory mega calculator | |
import svgwrite # Draw images with mathematical perfection for art at any scale cuz information theory. See: 3blue1brown on youtube | |
import pymidi # Write playable midi files! | |
# Most projects are a dozen to a few dozen files imported this way. You can organize functional units that can be dependent on each other's functionality | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment