Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,5 @@
X, Y = 0, 1
p = (3, 4)
p = [3, 4]
print p[X]

View file

@ -0,0 +1,7 @@
class Point:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
p = Point()
print p.x

View file

@ -0,0 +1,5 @@
class MyObject(object): pass
point = MyObject()
point.x, point.y = 0, 1
# objects directly instantiated from "object()" cannot be "monkey patched"
# however this can generally be done to it's subclasses

View file

@ -0,0 +1 @@
pseudo_object = {'x': 1, 'y': 2}

View file

@ -0,0 +1,27 @@
>>> from collections import namedtuple
>>> help(namedtuple)
Help on function namedtuple in module collections:
namedtuple(typename, field_names, verbose=False)
Returns a new subclass of tuple with named fields.
>>> Point = namedtuple('Point', 'x y')
>>> Point.__doc__ # docstring for the new class
'Point(x, y)'
>>> p = Point(11, y=22) # instantiate with positional args or keywords
>>> p[0] + p[1] # indexable like a plain tuple
33
>>> x, y = p # unpack like a regular tuple
>>> x, y
(11, 22)
>>> p.x + p.y # fields also accessable by name
33
>>> d = p._asdict() # convert to a dictionary
>>> d['x']
11
>>> Point(**d) # convert from a dictionary
Point(x=11, y=22)
>>> p._replace(x=100) # _replace() is like str.replace() but targets named fields
Point(x=100, y=22)
>>>