cropse

用Docker取代python的venv 2017- 3-28


alpine

apk update
apk add python3

Tag: docker python

View

Python iterator&generator 2017- 3-24


先講結論:
Iterator 是透過一個class 內部宣告__iter__還有__next__(python2 是next)方法來達成可迭代(iterable)的物件(class)
Genetator 是透過yield簡單產生一個iterator的方法(method)

這是一般的iterator

class iterator(object):
    def __init__(self, start, stop):
        self.start = start
        self.stop = stop
    def __iter__(self):
        return ...

Tag: python

View