Comments (8)
I guess so. It's possible it could be implemented, but you'll need to roll up your sleeves for that.
from pysnooper.
I'm guessing you didn't put the code in the file, but rather in some shell. I'm guessing that shell isn't IPython. Which shell is it?
from pysnooper.
I run the script on win10 python 3.11.0
It works correctlly
Output:
Starting var:.. number = 6
11:50:32.973112 call 4 def number_to_bits(number):
11:50:32.975097 line 5 if number:
11:50:32.976097 line 6 bits = []
New var:....... bits = []
11:50:32.976097 line 7 while number:
11:50:32.976097 line 8 number, remainder = divmod(number, 2)
Modified var:.. number = 3
New var:....... remainder = 0
11:50:32.977117 line 9 bits.insert(0, remainder)
Modified var:.. bits = [0]
11:50:32.977117 line 10 return bits
11:50:32.978115 return 10 return bits
Return value:.. [0]
Elapsed time: 00:00:00.005987
from pysnooper.
I get the same output when using Jupyterlab.
from functools import reduce
import pysnooper
@pysnooper.snoop()
def multi(x,y):
return x*y
print(reduce(multi,range(1,4)))
multi(5,2)
Output
Source path:... C:\Users\...\AppData\Local\Temp\ipykernel_17756\20432242.py
Starting var:.. x = 1
Starting var:.. y = 2
17:51:19.570314 call 4 SOURCE IS UNAVAILABLE
17:51:19.570314 line 6 SOURCE IS UNAVAILABLE
17:51:19.570314 return 6 SOURCE IS UNAVAILABLE
Return value:.. 2
Elapsed time: 00:00:00.000000
Starting var:.. x = 2
Starting var:.. y = 3
17:51:19.570314 call 4 SOURCE IS UNAVAILABLE
17:51:19.570314 line 6 SOURCE IS UNAVAILABLE
17:51:19.570314 return 6 SOURCE IS UNAVAILABLE
Return value:.. 6
Elapsed time: 00:00:00.000000
Starting var:.. x = 5
Starting var:.. y = 2
17:51:19.570314 call 4 SOURCE IS UNAVAILABLE
17:51:19.570314 line 6 SOURCE IS UNAVAILABLE
17:51:19.570314 return 6 SOURCE IS UNAVAILABLE
Return value:.. 10
Elapsed time: 00:00:00.000000
from pysnooper.
Calling just regular python repl from the command prompt:
Python 3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pysnooper
>>> def multi(x,y):
... return x*y
...
>>> with pysnooper.snoop()
File "<stdin>", line 1
with pysnooper.snoop()
^
SyntaxError: expected ':'
>>> with pysnooper.snoop():
... multi(5,2)
...
Source path:... <stdin>
New var:....... __name__ = '__main__'
New var:....... __doc__ = None
New var:....... __package__ = None
New var:....... __loader__ = <class '_frozen_importlib.BuiltinImporter'>
New var:....... __spec__ = None
New var:....... __annotations__ = {}
New var:....... __builtins__ = <module 'builtins' (built-in)>
New var:....... pysnooper = <module 'pysnooper' from 'C:\\Users\\....\\Ap....11\\Lib\\site-packages\\pysnooper\\__init__.py'>
New var:....... multi = <function multi at 0x000002049302E980>
18:03:12.070700 line 2 SOURCE IS UNAVAILABLE
10
18:03:12.071645 line 1 SOURCE IS UNAVAILABLE
Elapsed time: 00:00:00.000945
>>>
from pysnooper.
@Sionwage Thanks for reporting. It would be good to be able to get the source in these cases, but I probably won't work on this because it's not important enough for me. If you're interested feel free to dig in and implement it.
from pysnooper.
Ok, I think I found why I get the source is unavailable for me.
I was running this with Jupyterlab in a cell. If I move the function to a '.py' file like 'test.py' with this code:
import pysnooper
@pysnooper.snoop()
def adder(x, y):
answer = x + y
return answer
if __name__ == '__main__':
print(adder(5, 20))
and call the function from Jupyterlab by running this:
import test
test.adder(5, 20)
I get this output that matches the functionality outlined in the readme:
Source path:... C:\Users\...\OneDrive - ...\Documents\Python\temp\test.py
Starting var:.. x = 5
Starting var:.. y = 20
11:24:16.302453 call 4 def adder(x, y):
11:24:16.302453 line 5 answer = x + y
New var:....... answer = 25
11:24:16.302453 line 6 return answer
11:24:16.302453 return 6 return answer
Return value:.. 25
Elapsed time: 00:00:00.000000
25
I think that this cannot be used with its full functionality in Jupyterlab or Ipython unless there is an actual source file for PySnooper to scrape from?
from pysnooper.
I'm just tickled I got this working as it is very handy. This is probably my cue to get out of Jupyter and start using a more mature workflow.
from pysnooper.
Related Issues (20)
- Output to logging HOT 1
- Snoop recursively, but only in my code. HOT 2
- print value of a claas var HOT 1
- [feature request] Add command line color output for Windows HOT 7
- Feature request: python -m pysnooper user_script.py HOT 1
- Compatibility issue with Debugger in Visual Studio Code HOT 2
- Print("come") HOT 1
- compatiblity with python 3.12 HOT 7
- No variable output from the last line HOT 3
- Can not install it in Kaggle platform HOT 1
- `return` event line missing when exception occurred HOT 9
- new features request/discussion HOT 2
- Add Callback HOT 1
- Fix the CI HOT 4
- Deactivate all snooping except explicitly specified "watch"es HOT 3
- snoop entire file or program HOT 3
- Evaluate using `sys.monitoring` to make PySnooper faster
- [feature] only trace functions in specific files HOT 1
- about using multiprocessing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pysnooper.