Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/whittlbc/wat-py
Simple interactive breakpoint library with with automatic variable injection.
https://github.com/whittlbc/wat-py
Last synced: 3 months ago
JSON representation
Simple interactive breakpoint library with with automatic variable injection.
- Host: GitHub
- URL: https://github.com/whittlbc/wat-py
- Owner: whittlbc
- License: mit
- Created: 2018-05-05T00:00:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-15T19:34:01.000Z (over 6 years ago)
- Last Synced: 2024-11-02T00:08:51.818Z (3 months ago)
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 60
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# wat
Simple interactive breakpoint library with automatic variable injection, providing access to **both** local and global variables.
**Better than** `print` because you can actually interact with your variables.
**Better than** `code.interact` because you get both local and global variables.
**Better than anything else** because it's short and sweet, has no dependencies, and works with both Python 2 & 3.# Installation
```
$ pip install wat-py
```# Quickstart
```python
from wat import watwat() # set interactive breakpoint
```# Usage
### Set a breakpoint
Setting an interactive breakpoint is as easy as calling `wat()` from whatever line you want.
Example:
```python
# Example app.py file
from wat import wat
import urlliba = 1
b = 2def do_something():
a = 10
c = 3
wat()
# more code-sauceif __name__ == '__main__':
do_something()
```Running `app.py` will call the `do_something` function and pause code execution right after `c` is defined.
An interactive console will appear, giving you access to all vars (both local and global) that `do_something` would
otherwise have access to at the time of the breakpoint:```python
$ python app.py
(wat Interactive Console)
>>> a
10 # local var overwrites global var
>>> b
2 # global var
>>> c
3 # local var
>>> urllib
# imported module still available
```### Leave interactive console & proceed with code execution
`Ctrl+D`
### Leave interactive console without executing any more code
`exit()`
# Reason
The built-in `code.interact` method Python provides requires you to pass in the specific variables you want to have
available in the interactive console, which gives you the option of passing in `locals()`, `globals()`, or manually
creating a dict with the combination of both local and global vars (which no one wants to do every single time they want to set a breakpoint). I got sick of writing `import code; code.interact(local=locals())` whenever I needed to set a
breakpoint, realizing I needed some global vars from the import statements at the top of my file, and then having to
manually re-import those global vars.# License
MIT