bmalehorn / vscode-print-it

Wrap a print statment around current word or selection
3 stars 3 forks source link

[FEATURE REQUEST] use Python Icecream package instead, or optional #14

Open lundeen-bryan opened 8 months ago

lundeen-bryan commented 8 months ago

Would like to use the icecream package the way your extension does. Essentially instead of wrapping in a print statement, it would wrap in an ic statement.

Keep in mind user would have to use from icecream import ic

See the following page for details on the package https://github.com/gruns/icecream

bmalehorn commented 7 months ago

Would like to use the icecream package the way your extension does. Essentially instead of wrapping in a print statement, it would wrap in an ic statement.

Keep in mind user would have to use from icecream import ic

See the following page for details on the package https://github.com/gruns/icecream

Hi @lundeen-bryan, I didn't know about the icecream package, that's pretty neat!

Python 3.8+ actually has something like ic built in. For example, this statement:

ic(foo(123))
=> ic| foo(123): 456

can instead use the built in f-string = operator:

print(f"{foo(123)=}")
=> foo(123)=456

In fact, since I use always Python 3.8+ I put this in my personal VSCode config:

"print-it.python.template": "print(f\"{{{raw}}=}\")",

I'd recommend using that same setting.

But if you'd like to use icecream, you can add this to your personal config:

"print-it.python.template": "ic({{raw}})",

Does that make sense?

And overall, I'd rather not change the default setting. I want to support Python <3.8 (which rules out the f-string trick), and want to have it work without any installation required (which rules out icecream). I want it to work automatically for all users.

lundeen-bryan commented 2 months ago

Sorry I didn't reply back earlier I've been on another project. But I really apprreciate the tips because I can try to use this. Thanks again!