summaryrefslogtreecommitdiff
path: root/cs/Python.md
diff options
context:
space:
mode:
authornic <ra@afu.re>2025-05-05 10:59:25 -0400
committernic <ra@afu.re>2025-05-05 10:59:25 -0400
commit21ae09ada9d367994b3a00c14bce5836a806b899 (patch)
tree7572094d84b9c185245c84d3dea90e39932e7dcc /cs/Python.md
parent0567d6cd88c593b7d69df371a9804fa384c4b5d6 (diff)
Auto from nzxt - Mon 05 May 2025 10:59:25 AM EDT
Diffstat (limited to 'cs/Python.md')
-rw-r--r--cs/Python.md65
1 files changed, 65 insertions, 0 deletions
diff --git a/cs/Python.md b/cs/Python.md
new file mode 100644
index 0000000..bc08ed2
--- /dev/null
+++ b/cs/Python.md
@@ -0,0 +1,65 @@
+Python does not have a classpath and unless you are root, you can't install new pkg for the whole system
+
+# pip installs in
+
+.local/lib/
+
+
+virtualenv - solution to pkg management? - isolated space with own instance of python
+
+virtualenv TESTENV -p python
+source TESTENV/bin/activate
+# to get out of env
+deactivate
+
+** exponant
+
+x = 'Mark'
+len(x) - function
+x.upper() - method
+
+dir() - built it give directory of an object (all methods available)
+with no arg show you all name in global namespace
+
+dir() == sorted(globals().keys())
+
+gloabls() == locals()
+
+super() - goes trought inheritance chain and return the class that is after the one passed as the function first argument. Can by used to bypass modification made by earlier classes.
+
+
+# Data containers
+
+list() - []
+dict() - {}
+tuple() - ()
+set() - set()
+
+
+
+__ init__ - where to assign instance specific attributes when object first constructed
+__ str__ - control how object is printed
+__ repr__ - object output when interactive shell
+__ eq__ - uniquely identify all created object
+
+
+1st time you import a modules python execute the code inside it.
+2nd time will not re-run the code. (usefull when import multiples modules that import all the same modules)
+importlib if want to reload modules so run more than once
+
+When importing a module you can use it's defined functions, classes, constants etc...
+Access those thing by putting the module name as prefix before the function
+
+import X
+import X as x
+from X import x
+from X import x as x
+
+when you run a modules as a script __ name__ becomes __ main__
+
+
+__ init__.py - required to tell python dir is a pkg (initialise a pkg) REQUIRED
+used to set the __ all__ variable & import submodules
+
+
+