I decided to try replying through the HyperKitty archived interface, where I’ve
been examining the cosmetics of [our
thread](https://mail.python.org/archives/list/[email protected]/thread/H6KKJR57V7G4CIPDPJ7FUCXWDHMRUYUT/
<https://mail.python.org/archives/list/[email protected]/thread/H6KKJR57V7G4CIPDPJ7FUCXWDHMRUYUT/>)
to date with a critical eye.
Also, I see I said “construct manager” a few times when I was meaning “context
manager” — oh well.
Hyperkitty pops me into an Apple mail client I never use. Some default Apple
setting somewhere I suppose I could dig up. Lets see if this sends or will I
end up cutting and pasting to Gmail in Chrome.
Yes Wes, you’re pretty close on your educated guess/memory re that
semi-esoteric species of class (the context manager), wherein ```__enter__```
is what actually returns the object of the optional “as” as in:
with DB(“users”) as db: # <— optional object returned by ```__enter__``` which
takes no args
indented block
```__exit__``` triggered on exit, has info in args re any exceptions, I use
*oops to gather up the 3-tuple.
outdented (db stays available but __exit__ will have likely closed the
connection, e.g. hung up the phone on the database)
The arguments to class DB() go to the optional ```__init__``` as always,
however ```__enter__``` gets to return the “db” (above) which then becomes
available to the indented block (suite as Holden calls it) as a potentially
useful object. Most typically ```__enter__``` simply returns the self (the
instance of the context manager class itself). However in principle it’s free
to return any object it likes, similar to ```__iter__``` (which should at least
return an iterator, but only self if self is already such, per class generator
API where ```__next__``` must also be there).
[My
pattern](https://github.com/4dsolutions/python_camp/blob/master/ContextManager.ipynb
<https://github.com/4dsolutions/python_camp/blob/master/ContextManager.ipynb>)
is to load up the target object db with a lot of tools for working with the
database at hand, much as open(filename) may be use with with to create the
filetype object. On ```__exit__``` the database closes. In between, I might
even db.zap_tables() and db.create_tables(). Sometimes my DB is very
customized to work with a very specific database. Other times I separate the
```__enter__``` ```__exit__``` part, could be a parent helper. The linked
Notebook gives more context.
Yes, completely agree on Jake Vanderplas as a go to guy for anything both
pythonic and data scientific.
From my campsite FAQ:
Q: Where's a good place to begin with data science?
A: Follow Jake Vanderplas <http://vanderplas.com/> and study his work.
Wes, your pull requests came in smoothly and my current plan is to exhibit this
program as is, as an example of what [super duper fluent
Python](https://github.com/4dsolutions/python_camp/blob/master/camper_program.py
<https://github.com/4dsolutions/python_camp/blob/master/camper_program.py>)
actually looks like, with unit testing and the whole business.
I might use git to dig up an old version (say from this last Monday), showing
how ancient drafts might still be excavated in a repo, and then roll forward
again, to the way it is now. That’s what git’s good for kids!
I did the pull request process online for campers to observe, and commented on
closing the request, how smoothly it all went.
I’m hoping my practice of outlining a course in a hyperlink-rich Jupyter
Notebook will continue to spread, not that I invented it or anything. I’m
telling my campers this generic Notebook technology (not just Jupyter) is what
their high schools might well be using soon, if not already.
I’m eager to pack in a lot of serious academic content given these ["covid
camps”](https://flic.kr/p/2iLG2qU <https://flic.kr/p/2iLG2qU>) aren’t just
“summer camp”. They’re a continuation of their ordinary schooling, in a
homeschooling context.
Kirby
_______________________________________________
Edu-sig mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/edu-sig.python.org/