Hackfut Security File Manager
Current Path:
/usr/lib64/python2.6/Demo/classes
usr
/
lib64
/
python2.6
/
Demo
/
classes
/
📁
..
📄
Complex.py
(9.72 KB)
📄
Complex.pyc
(9.84 KB)
📄
Complex.pyo
(9.84 KB)
📄
Dates.py
(7.64 KB)
📄
Dates.pyc
(7.23 KB)
📄
Dates.pyo
(7.23 KB)
📄
Dbm.py
(1.54 KB)
📄
Dbm.pyc
(2.47 KB)
📄
Dbm.pyo
(2.47 KB)
📄
README
(522 B)
📄
Range.py
(3.05 KB)
📄
Range.pyc
(4.03 KB)
📄
Range.pyo
(4.03 KB)
📄
Rev.py
(2 KB)
📄
Rev.pyc
(2.82 KB)
📄
Rev.pyo
(2.82 KB)
📄
Vec.py
(1000 B)
📄
Vec.pyc
(2.61 KB)
📄
Vec.pyo
(2.61 KB)
📄
bitvec.py
(10.25 KB)
📄
bitvec.pyc
(10.16 KB)
📄
bitvec.pyo
(10.16 KB)
Editing: Vec.py
# A simple vector class def vec(*v): return Vec(*v) class Vec: def __init__(self, *v): self.v = list(v) def fromlist(self, v): if not isinstance(v, list): raise TypeError self.v = v[:] return self def __repr__(self): return 'vec(' + repr(self.v)[1:-1] + ')' def __len__(self): return len(self.v) def __getitem__(self, i): return self.v[i] def __add__(self, other): # Element-wise addition v = map(lambda x, y: x+y, self, other) return Vec().fromlist(v) def __sub__(self, other): # Element-wise subtraction v = map(lambda x, y: x-y, self, other) return Vec().fromlist(v) def __mul__(self, scalar): # Multiply by scalar v = map(lambda x: x*scalar, self.v) return Vec().fromlist(v) def test(): a = vec(1, 2, 3) b = vec(3, 2, 1) print a print b print a+b print a-b print a*3.0 test()
Upload File
Create Folder