A vscode extension to quickly print variable, variable type, tensor shape etc by using shortcuts

Overview

Quick Python Print

This repo is inspired by "Python Quick Print". "Python Quick Print" can quickly print out variables on the console by using shortcut Ctrl+Shift+L, while "Quick Python Print" enhance some features:

  • You can put the cursor at target line, the extension will automatically recognize the variable in the line.
  • Press Ctrl+Shift+O to print out tensor shape, e.g. print("==>> a.shape: ", a.shape).
  • Press Ctrl+Shift+T to print out variable type, e.g. print("==>> type(a): ", type(a)).
  • Press Ctrl+Shift+; to insert print("".center(50, "-")) used for printing separator line.
  • Move the cursor inside the bracket if insert simply print().
  • Press Ctrl+Shift+/ to comment out or uncomment all print statement in the scope.
  • Press Ctrl+Shift+R to delete all print statements in the scope.
  • Allow user to define customized prefix and suffix of print content flexibly in extension settings.
  • Able to output colored text in terminal by using python built-in package: termcolor.

If you find bug or have feature request, you can check out the ChangeLog to see if this bug or feature had been fixed or added in latest version, if not, welcome to post in this extension's github repo.

Motivation

When I am learning deep learning model, I often want to know how the tensor shape changes along the way, I think this will help me understand how the deep learning model works. Take pytorh for example, these operations view,slice,concat,permute,conv,linear etc all will change the tensor shape. Fortunately, many deep learning framework all have .shape attribute of tensor(as far as I know, there are pytorch, numpy, tensorflow, paddlepaddle, oneflow), so this makes the extension be useful for different deep learning framework users, afterwards, I add more features to make it also useful for other python developer.

Installation

Before installation, make sure your vscode version ≥ 1.57.0. This extension is available in the Visual Studio Code Extension Marketplace, you can search "Quick-Python-Print" and install it.

How to use

Introduction video: Bilibili | Youtube (When I made this video, it was version 0.1.1, and there have been many changes in the current version)

This extension only activates within .py and .ipynb files

Keyboard Shortcut

For Mac user, the Ctrl should be Cmd.

Ctrl+Shift+L

Select the variable, then press Ctrl+Shift+L, it will insert print statement at next line:

You can also just put the cursor at the target line, then the extension will automatically recognize the variable:

If you didn't select variable or the extension can't recognize variable, it will just insert simply print() and move the cursor inside it. If selected variable is new defined for the first time, insert code at current line :

Ctrl+Shift+O

Ctl+Shift+O is similar to Ctrl+Shift+L except that it will print tensor shape by default:

Ctrl+Shift+T

Ctl+Shift+T is similar to above except that it will print type of variable by default:

Ctrl+Shift+/

Comment out or uncomment the print statement in the python file or in the selected scope:

Ctrl+Shift+up

Comment out all print statement above the cursor in the python file:

Ctrl+Shift+down

Comment out all print statement below the cursor in the python file:

Ctrl+Shift+;

Insert a print statement that will print 50 - to become a delimiter like --------------------------------------------------:

Ctrl+Shift+R

Delete all the print statement(include those commented) in the python file or in the selected scope::

Compatibility with different framework

Many deep learning framework all have .shape attribute of tensor:

If any of these shortcuts conflicts with existing shortcut, you may change it in the Keyboard Shortcuts Setting: Press Cmd+P or Ctrl+P and type in >Open Keyboard Shortcuts. Search for the conflict shortcut, then you will find those shortcut using the same keys, then right click one of them, modify or delete keybinding.

Extension Settings

This extension has following settings:

You can go to the Extension Settings to modify them to suit your preferences. After modification, it should take effect immediately.

Color output text

To color the output text in terminal, you need to do these things:

  1. Go to Extension Settings, check the 5.enable-colored-output-text to be true. And you can select the color you like from the drop-down list.
  2. Add from termcolor import colored in the python file
  3. Now Press Ctrl+Shift+L or Ctrl+Shift+O or Ctrl+Shift+T will insert the print statement that can color output text.
  4. Run Python File in Terminal.

More

I also make a pypi package : printensor to uppack tensors inside list, tuple, dict, generator, then print their tensor shape. After installing and import, you can replace print( with prints( to intergrate with this extension.

Known issue

This extension can not handle tensor that cross multiple lines, for example:

a = torch.tensor([[1.0, 2.0, 3.0], 
                [4.0, 5.0, 6.0]])

You can use Alt + down to move down the inserted code.

Warning

This uses Python 3 syntax,If you're using Python 2 print isn't a function.You can import this behavior from __future__: from __future__ import print_function

Donation

If you find this extension can help you save time, and willing to donate me, i would be very grateful !

🥤 Buy me a Coca-Cola

License

MIT License

You might also like...

Browser extension to add more keyboard shortcuts to twitter.com.

Browser extension to add more keyboard shortcuts to twitter.com.

Twitter Shortcut Plus Browser extension to add more keyboard shortcuts to twitter.com. Keyboard shortcuts Browse Browse links in background (default:

Jun 4, 2022

we learn the whole concept of JS including Basics like Object, Functions, Array etc. And Advance JS - Understanding DOMs, JQuery, Ajax, Prototypes etc.

JavaScript-for-Complete-Web Development. we learn the whole concept of JS including Basics like Object, Functions, Array etc. And Advance JS - Underst

Jul 22, 2022

Minifies css variable names

PostCSS Variable Compress postcss-variable-compress is a PostCSS plugin minifies variable names and saves space. Even if you have 1295 css variables s

Nov 19, 2022

Make the content slide prettily across the screen with variable sizes of scrolling items, in any of four directions, pausing while the mouse is over the marquee, and all with vanilla JavaScript.

TEG Marquee Make the content slide prettily across the screen with variable sizes of scrolling items, in any of four directions, pausing while the mou

Dec 30, 2021

An in-browser JavaScript variable dumper, similar in functionality to ColdFusion's cfdump tag.

prettyPrint.js © James Padolsey prettyPrint.js is an in-browser JavaScript variable dumper, similar in functionality to ColdFusion's cfdump tag. First

Sep 18, 2022

Self-hosted environment variable management platform

Self-hosted environment variable management platform

envplat - environment platform This project is under development. Please contact me for any information or collaboration. Self-hosted environment vari

Apr 25, 2022

Combine type and value imports using Typescript 4.5 type modifier syntax

type-import-codemod Combines your type and value imports together into a single statement, using Typescript 4.5's type modifier syntax. Before: import

Sep 29, 2022

JSDoc generator for JavaScript, TypeScript using AI. (VSCode extension)

JSDoc generator for JavaScript, TypeScript using AI. (VSCode extension)

JSDoc generator for JavaScript, TypeScript using AI. (VSCode extension)

Aug 18, 2022

Easily create key board shortcuts for your JS functions. Built using JS only with no other dependency. Inspired from MacOS spotlight

floodlightjs Inspired from macOS spotlight, floodlight is simple JS library that will show a search area. How the search is handled is completely on y

Aug 12, 2022
Owner
weida wang
weida wang
ndarray/tensor data processing for modern browsers

nadder Easy n-dimensional data manipulation with NumPy syntax. Installation npm i nadder # or yarn add nadder, or pnpm add nadder Usage import { ndarr

null 16 Dec 23, 2022
Fast Differentiable Tensor Library in JavaScript and TypeScript with Bun + Flashlight

A fast differentiable tensor library for research in TypeScript and JavaScript. Built with bun + flashlight. ⚠️ This is experimental software! ⚠️ Usag

Meta Research 917 Jan 7, 2023
a vscode extension for http response data auto transform ts type.

Api2ts 这是一个自动将 http 的响应数据转化为 ts 的类型,使用 json-to-ts 做的。 Features 框选配置项后,使用快捷键 alt+Q : 请求参数配置文件 在根目录下创建 Api2ts.config.json 文件,配置项如下: { "baseURL": "http

phy-lei 6 Jun 30, 2022
VSCode Extension & utilities for exploring TypeScript type information

ts-type-explorer VSCode Extension & utilities to explore type information in TypeScript projects. Installation Check out the releases page to download

Max Stoumen 6 Nov 20, 2022
Obsidian plugin: Type text shortcuts that expand into javascript generated text.

Obsidian Plugin - Text Expander JS (open beta) This Obsidian plugin allows the user to type text shortcuts that are replaced by (or "expanded into") j

Jon Heard 79 Dec 27, 2022
A very simple image slider that will responsively work with images of any size or shape

Square1 A very simple image slider that will responsively work with images of any size or shape. requires jQuery Demo Installation Link to jQuery <sc

Thom 9 May 20, 2022
Full dynamic tool kit that is capable of deobfuscating and producing a javascript representation of Shape's Virtual Machine obfuscation

Shape Security Decompiler Tool-Kit This tool kit is capable of dynamically deobfuscating all versions of shape security's virtual machine interpreter

null 25 Dec 15, 2022
VSCode plugin to display interactive decompilation in the editor using various decompilers (binja, Ghidra, jd, dnspy, etc)

code-decompiler README This is SUPER WIP!!! Don't use it yet! All that is working so far is: Create memfs to store decomp results Compile protobuf to

null 3 Jul 30, 2022
Craftcuts - a Shortcuts eXtension for Craft

Craftcuts Welcome to the repository of Craftcuts my Shortcuts eXtension for Craft. Please read through the instructions, especially the installation c

FlohGro 35 Dec 31, 2022
Browser extension to add more keyboard shortcuts to TweetDeck.

TweetDeck Shortcut Plus Browser extension to add more keyboard shortcuts to TweetDeck. Keyboard shortcuts Browse Browse tweet (default: alt+b) Browse

Ryo Nakamura 5 May 26, 2022