giving up

This commit is contained in:
lda committed 2025-01-31 22:51:36 +07:00
1 parent d1a042206c
commit 4f8830ab5f
4 files changed
+302 -16

No files matched your search

+25 -10
View File
@@ -476,6 +476,10 @@ from collections import namedtuple
from numbers import Number
from typing import Self
# a habit that you should take is that you should never blanket import.
# non of these import * in python, use ::* in rust, using namespace in c++, etc.
# only import what you need. the IDE will help you.
class BungeeJumper:
"""
@@ -517,8 +521,8 @@ class BungeeJumper:
@property
def t(self):
"""current time
we will not set time, change it through delta + special reset fn,
"""
we will not set time, change it through delta + special reset fn,"""
return self.__time
@property
@@ -590,6 +594,7 @@ class BungeeJumper:
"table": [i._asdict() for i in self.__table],
}
# pylint flagged this for design choice, and i agree.
def bungee_import(self, t=None, dt=None, vt=None, m=None, cd=None, table=None):
"""overrides, also format from bungee_info only"""
if t is not None:
@@ -665,16 +670,16 @@ instance instead of doing nothing will be passed into methods as first argument.
yes, not javas `this`. `this` is a set name.
python `self` i could change it to whatever. instance will be passed to it.
That is a classmethod.
That is a method.
a staticmethod has no such rules.
"""
# do you know you can declare a class without even touching the word class at all? its the power of type().
# however dont do this oh please
@classmethod
def lda_set_example_arg(self, arg):
self.lda_example_instance_arg = arg
def lda_set_example_arg(inst, arg):
inst.lda_example_instance_arg = arg
" __init__ is a magic function that will run when you make a class instance"
@@ -694,13 +699,18 @@ LdaExampleClass = type(
LdaExampleClass.hello_to("lda") # prints hello lda!
def lda_print_example_arg(self):
print("instance:", self.lda_example_instance_arg)
print("class:", self.lda_example_class_arg)
def lda_print_example_arg(inst):
print("instance:", inst.lda_example_instance_arg)
print("class:", inst.lda_example_class_arg)
# @classmethod # class methods passes class as opposed of instance for first arg # i just knew this!
# def cls_print_example_arg(cls):
# print("class:", cls.lda_example_class_arg)
# print("instance:", cls.lda_example_instance_arg) # uh oh
# objects can freely add properties
LdaExampleClass.lda_print_example_arg = classmethod(lda_print_example_arg)
LdaExampleClass.lda_print_example_arg = lda_print_example_arg
# LdaExampleClass.cls_print_example_arg = cls_print_example_arg # see note below
lda1 = LdaExampleClass(3) # this must fit the args of self.__init__()
lda1.lda_print_example_arg() # pylint: disable=no-member # ide freak out
@@ -708,6 +718,7 @@ lda1.lda_print_example_arg() # pylint: disable=no-member # ide freak out
# and class which is from the above which is 1.
# Nothing was changed: i dont assign anything to anything in the functions
# except for lda_set_example_arg
# lda1.cls_print_example_arg() # crashes as cls LdaExampleClass dont have lda_example_instance_arg instance variable
# dont do this, however, as ide will freak out.
@@ -723,6 +734,7 @@ copied_1_20 = one_to_20.copy() # this shallow copies
copied_1_20.append(21)
assert copied_1_20 != one_to_20
assert copied_1_20[-2:] == [20, 21]
# if you have intellicode you can do ctrl + space to get that hints going.
@@ -731,3 +743,6 @@ ah yes intellicode.
You can view methods easily with intellisense if using vscode,
and you can also docs.python.org for more
"""
# here is where you should be downloading jupyter to get the Tutorial2 Going.
# check its website. make sure you have the python, it is in PATH, and the pip exists. Or you can use poetry or miniconda. Or pipx. idfk do research.
+93 -6
View File
@@ -58,9 +58,9 @@
"source": [
"try:\n",
" x\n",
"except NameError: # last code block define x\n",
"except NameError: # last code block define x\n",
" print(\"play the last code block broski\")\n",
"else: # last code block ran\n",
"else: # last code block ran\n",
" print(\"thats right\")"
]
},
@@ -224,7 +224,7 @@
" print(\"no way\")\n",
" case 5:\n",
" print(\"2 + 3 = 5\")\n",
" case x if x > 6: # match doesnt need to cover all cases\n",
" case x if x > 6: # match doesnt need to cover all cases\n",
" print(\"woah\")"
]
},
@@ -250,7 +250,7 @@
"try:\n",
" raise ValueError(\"value eroe\")\n",
"except ValueError as error:\n",
" print(\"raised\", error)\n"
" print(\"raised\", error)"
]
},
{
@@ -284,7 +284,8 @@
"\n",
" def quux(tis, arg1):\n",
" return arg1, 42\n",
" \n",
"\n",
"\n",
"# usage:\n",
"\n",
"fbar = Foo()\n",
@@ -340,6 +341,92 @@
"source": [
"do research broski\n",
"\n",
"## more python stuff\n",
"\n",
"### map and filter\n",
"\n",
"alot of time you would want to do stuff with the List and you would want to have a look at the builtin `map()` or `filter()` or those kind of functions:\n",
"\n",
"what they do is:\n",
"\n",
"```python\n",
"collection = [something, something_else,]\n",
"def function(x) -> y: ...\n",
"\n",
"new_collection = map(function, collection) \n",
"# => each x you run function on it and it returns y.\n",
"# put that y in the place x would be in the new_collection\n",
"\n",
"condition = lambda x: x == True\n",
"# lambda is a kind of mini throwaway function. you know closures? yes that\n",
"# but it can only do one thing. one singular expression fits in there. life is bad.\n",
"# tips. use def if this function deserves a name. for example ReLU is just\n",
"# ReLU = lambda x: x if x > 0 else 0\n",
"# but you would use want to do def ReLU(x: float) -> float as much as possible\n",
"\n",
"filtered_collection = filter(condition, collection)\n",
"# check for condition for each element of condition and append it into filtered_collection\n",
"```\n",
"\n",
"remember map and filter doesnt return a list back but a special generator object so you would have to call list() on it to use as list.\n",
"\n",
"why? for performance. generator is lazy."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"we also have this thing:\n",
"\n",
"### Python list comprehension\n",
"\n",
"comprehension. fuck do i know what it means. you dont know half these words and so do i.\n",
"\n",
"a simple way to do fiter_map ig"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# you would do this:\n",
"oldlist = list(range(1, 40, 3))\n",
"newlist = []\n",
"for i in oldlist: # notice this\n",
" if i % 5 == 0: # notice this\n",
" newlist.append(i)\n",
"\n",
"list_shorthand = [i for i in oldlist if i % 5 == 0]\n",
"\n",
"assert list_shorthand == newlist # same thing!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"its: \n",
"```python\n",
"something(vals) for vals in collection if condition(vals) if condition2(vals) if etc.\n",
"```\n",
"and `something(vals)` could well be another comprehension.\n",
"\n",
"notice for in if. strictly for in if, and not if for in. that if is of something else.\n",
"\n",
"oh but `something if condition else something_else` i also see how is that\n",
"\n",
"well that is another shorthand unrelated, but if you can use sure go ahead\n",
"\n",
"its kinda like the Ternary conditional operator `cond ? true_expr : false_expr` in c or typescript and yes you can go crazy with it just like with typescript"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## what the fuck is this half code half document\n",
"\n",
"jupyter. very flexible very dynamic. you can have jupyter running on browser or on vscode i think\n",
@@ -368,7 +455,7 @@
"except ImportError:\n",
" print(\"python -m pip install numpy\")\n",
"else:\n",
" print(np.array([[1, 5, 7], [2, 6, 8], [3, 4, 9]]))\n"
" print(np.array([[1, 5, 7], [2, 6, 8], [3, 4, 9]]))"
]
},
{