[CentralOH] 2017-05-05 道場 Scribbles 落書/惡文? hardware details; restrictor plate racing; good and bad _; generators; iterator protocol

jep200404 at columbus.rr.com jep200404 at columbus.rr.com
Mon May 8 22:48:44 EDT 2017


cat /proc/cpuinfo | less
    vmx or svm are good to have
lscpu
lspci
lsusb
sudo dmidecode | less

wp:Multi-channel memory architecture
wp:Restrictor plate

wp: prefix means Wikipedia
To get good answers, consider following the advice in the links below.
http://catb.org/~esr/faqs/smart-questions.html
http://web.archive.org/web/20090627155454/www.greenend.org.uk/rjk/2000/06/14/quoting.html

Use _ as name of variable that is not used.
That is a convention that came from Ruby.
Dunno where it ultimately came from.
_ is also name of last result in interactive python

    (jupy) doj at 4519n_high:~$ python
    Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 12:22:00)
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> [i*i for i in range(3)]
    [0, 1, 4]
    >>> _
    [0, 1, 4]
    >>> import random
    >>> random.randint(1, 5)
    2
    >>> [random.randint(1, 5) for i in range(5)]
    [1, 1, 2, 4, 3]
    >>> [random.randint(1, 5) for _ in range(5)]
    [4, 2, 5, 5, 3]
    >>> _
    [4, 2, 5, 5, 3]
    >>> 2 + 2
    4
    >>> _
    4
    >>>

showed some scary code that did something like
from foo import bar as _
That's a nasty use of _ as a name.
Imagine debugging it by pasting it into interactive python prompt,
then you do:

    >>> 2 + 2

and your precious import is gone.

asked about and learned a little bit about greatness of generators

start here: (thanks again XY!)

    https://mail.python.org/pipermail/centraloh/2013-June/001718.html
    (which leads to dabeaz's great stuff)

then play with:

    http://nbviewer.jupyter.org/github/cohpy/challenge-201605-generators/tree/master/
    http://nbviewer.jupyter.org/github/cohpy/challenge-201605-generators/blob/master/james-prior/8-nested-generators-20160626-1920.ipynb
        this one gets into several tricky things
            closures
            decorators
            operator overloading

It's not too late to add more stuff to that old challenge.

folks learning generators should learn the iterator protocol also.
Here's a stupid little generator.

    (jupy) doj at 4519n_high:~$ python
    Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 12:22:00)
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> def foo():
    ...     yield 'hello'
    ...     yield 3.1415926
    ...     yield ('eeny', 'meeny', 'miney', 'mo')
    ...
    >>> f = foo()
    >>> f
    <generator object foo at 0x7fe6483d2888>
    >>> next(f)
    'hello'
    >>> next(f)
    3.1415926
    >>> next(f)
    ('eeny', 'meeny', 'miney', 'mo')
    >>> next(f)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    StopIteration
    >>> for x in foo():
    ...     print(x)
    ...
    hello
    3.1415926
    ('eeny', 'meeny', 'miney', 'mo')
    >>>

two weeks away:
southernohioforestrally.com

how's your code?
https://xkcd.com/1833/

Editing Your Own OpenStreet Maps
http://www.linuxjournal.com/content/editing-your-own-openstreet-maps


More information about the CentralOH mailing list