

GitHub - whittlbc/wat-py: Simple interactive breakpoint library with with automa...
source link: https://github.com/whittlbc/wat-py
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md
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
from wat import wat wat() # set interactive breakpoint
Usage
Set a breakpoint
Setting an interactive breakpoint is as easy as calling wat()
from whatever line you want.
Example:
# Example app.py file from wat import wat import urllib a = 1 b = 2 def do_something(): a = 10 c = 3 wat() # more code-sauce if __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 app.py (wat Interactive Console) >>> a 10 # local var overwrites global var >>> b 2 # global var >>> c 3 # local var >>> urllib <module 'urllib' from ...> # 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
Recommend
-
52
Python has long had a default debugger named pdb in the standard libraries. pdb defines an interactive source code debugger for python programs. The intentions of this post is to clarify through examples and explanations...
-
7
Responsive day out 3: the final breakpoint 20 June 2015 ・ category: write-ups Yes...
-
8
Automa An extension for automating your browser by connecting blocks. From auto-fill forms, doing a repetitive task, taking a screenshot, to scraping data of the website, it's up to you what you want to do with this extension....
-
6
Dec 1, 2021 — 17:36 CUT How to Batch Convert Shortcuts for Use Throughout Monterey and with Other Automation Apps
-
7
Security Fixes Won't Require Full iOS Update in iOS 16, Will Be Installed AutomaticallyMonday June 6, 2022 1:46 pm PDT by Juli Clov...
-
23
Automa网页自动化神器 Aug 16, 2022 14:29 · 847 words · 2 minute read...
-
8
apk.sh apk.sh is a Bash script that makes reverse engineering Android apps easier, automating some...
-
10
Making the Social Web a Better Place: ActivityPub for WordPress Joins the Automattic Family If you’re a blogger or content creator who wants to reach a wider audience, the ActivityPub plugin is perfect for yo...
-
4
Volkswagen ID.4 electric SUV will qualify for the full $7,500 tax credit, automaker says / The ID.4 was initially left off the federal government’s list of qualifying EVs. But now it’s back on, thanks to local assembl...
-
10
效率神器!浏览器自动化操作插件:Automa
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK