Re: back to school... "1/3" --> float question, just eval?
![](https://secure.gravatar.com/avatar/e4d005fd33f12f0ac7ef49852a35e7c2.jpg?s=120&d=mm&r=g)
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/edu-sig@python.org/thread/H6KKJR57V7G4... <https://mail.python.org/archives/list/edu-sig@python.org/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
![](https://secure.gravatar.com/avatar/e4d005fd33f12f0ac7ef49852a35e7c2.jpg?s=120&d=mm&r=g)
Yikes. My attempt at hand-coding markdown links formatting as [word]( http://address) didn't work well at all in the HyperKitty Mailman3 view, my apologies. Here are the links again, in the order linked... This thread: https://mail.python.org/archives/list/edu-sig@python.org/thread/H6KKJR57V7G4... My context manager pattern: https://github.com/4dsolutions/python_camp/blob/master/ContextManager.ipynb Super fluent thanks to Wes (pull requests): https://github.com/4dsolutions/python_camp/blob/master/camper_program.py "Covid Camps" (souvenir): https://flic.kr/p/2iLG2qU Kirby
![](https://secure.gravatar.com/avatar/63ca18e130d527d0741f1da54bb129a7.jpg?s=120&d=mm&r=g)
Glad to help! There's so much time to learn during quarantine! Writing tests for myself because I <3 them so much; and because they're the missing half of the code. Like camper_program.py, IPython is a REPL (Read Evaluate Print Loop :) ```bash $ pip install ipython; ipython ``` ```python
? %? %logstart -h %logstart -o output_from_this.shell.py
## Contents
- Quick Git/GitHub tutorial (and a link to the relevant diff of the PR
(after syntax cleanup); should've `git tag` -ed this revision)
- GitLab tutorial
- Jupyter Notebook / JupyterLab keyboard shortcuts
## Quick Git/GitHub tutorial:
- Open the GitHub repo:
https://github.com/4dsolutions/python_camp
- Navigate to the file:
- Type `t` to activate the file finder ('?' shows help)
- Type `camper_`
- Press <Enter>
https://github.com/4dsolutions/python_camp/blob/master/camper_program.py
- Click the **History** button at the top right
`git log --oneline ./camper_program.py`
`git log --pretty=oneline; git log --help`
https://github.com/4dsolutions/python_camp/commits/master/camper_program.py
- Find "CLN: camper_program.py: pyflakes: is False, not in" (b95fff4)
`git show b95fff4`
- Click the **<>** button to "Browse the repository at this point in the
history"
https://github.com/4dsolutions/python_camp/tree/b95fff439ef3750ad7eaac146f6c97be64f7e2c0
https://github.com/4dsolutions/python_camp/tree/b95fff4
- Navigate to the `camper_program.py` file:
https://github.com/4dsolutions/python_camp/blob/b95fff439ef3750ad7eaac146f6c97be64f7e2c0/camper_program.py
https://github.com/4dsolutions/python_camp/blob/b95fff4/camper_program.py
- Compare between commits
`git diff b95fff4 master -- camper_program.py`
- vim:
`git difftool --tool=vimdiff b95fff4 master -- camper_program.py` (
requires vim )
- vscode:
`git difftool -x "code --wait --diff" b95fff4 master --
camper_program.py`
https://stackoverflow.com/questions/51316233/how-can-i-see-git-diff-on-visual-studio-code-side-by-side-file/56237464#56237464
- github:
https://help.github.com/en/github/committing-changes-to-your-project/comparing-commits
https://github.com/4dsolutions/python_camp/compare/b95fff4..master
- Click the Unified / **Split** button at the top right
- Click the Showing '5 changed files` link
- Click 'camper_program.py' (to jump to that file in the diff)
https://github.com/4dsolutions/python_camp/compare/b95fff4..master?diff=split#diff-eeb571aff0d4c7b51323fda6f2211df7
GitHub Keyboard Shortcuts:
https://help.github.com/en/github/getting-started-with-github/keyboard-shortcuts
...
GitLab's interface is a bit different:
Here's the *merge request* that added Markdown support to HyperKitty:
https://gitlab.com/mailman/hyperkitty/-/merge_requests/160
# Review the pipeline job log
- Click "Pipelines"
- Click the check mark in the status column (or the build number) of the
first row (the most recent GitLab CI Pipeline)
- Click the "py37-django-3.0" job in the Test column
- Scroll through the job log
- Find "Creating test database for alias 'default'..."
- Find "Ran 288 tests in 210.467s"
# Review the merge request (the MR diff)
- Click and hold the browser back arrow (to see history); move the mouse to
the merge request page title; release the mouse
- Click the "Changes" tab
- Click the icon to the left of "Compare"
GitLab Keyboard Shortcuts:
https://docs.gitlab.com/ce/user/shortcuts.html
https://docs.gitlab.com/ee/user/shortcuts.html
...
I could create a Jupyter notebook from this almost- Markdown email.
I could've just created a notebook and saved it as markdown manually (or
automatically with jupytext) and pasted it as this email.
To create a notebook from this:
- Single-click at the beginning of this email, <Shift>Click at the End,
<Ctrl-C> to Copy
- Create new notebook- Select the first cell, press <Esc> (to enter command
mode), then press M (to make a markdown cell)- Press <Enter> (to enter edit
mode)
- <Ctrl-V> to paste- <Ctrl-Shift-Minus> [ <Ctrl-+> ] to split the cell at
the cursor
Jupyter Notebook keyboard shortcuts:
- Open a notebook
- Help > Keyboard Shortcuts
Jupyter Lab keyboard shortcuts:
- <Ctrl-Shift-C> to open the Command Palette
On Sat, Apr 11, 2020 at 3:56 PM kirby urner <kirby.urner@gmail.com> wrote:
>
> Yikes. My attempt at hand-coding markdown links formatting as [word](
> http://address) didn't work well at all in the HyperKitty Mailman3 view,
> my apologies.
>
> Here are the links again, in the order linked...
>
> This thread:
>
> https://mail.python.org/archives/list/edu-sig@python.org/thread/H6KKJR57V7G4CIPDPJ7FUCXWDHMRUYUT/
>
> My context manager pattern:
> https://github.com/4dsolutions/python_camp/blob/master/ContextManager.ipynb
>
>
> Super fluent thanks to Wes (pull requests):
> https://github.com/4dsolutions/python_camp/blob/master/camper_program.py
>
> "Covid Camps" (souvenir):
> https://flic.kr/p/2iLG2qU
>
> Kirby
>
>
> _______________________________________________
> Edu-sig mailing list -- edu-sig@python.org
> To unsubscribe send an email to edu-sig-leave@python.org
> https://mail.python.org/mailman3/lists/edu-sig.python.org/
>
participants (2)
-
kirby urner
-
Wes Turner