I'm trying to work through the docs for Python's profile(rs). I'm using Python 3.6 in Anaconda on a Win10 laptop.
https://docs.python.org/3/library/profile.html
import cProfile
import re
cProfile.run('re.compile("foo|bar")')
This executes no problem, per the docs.
However,
import pstats
from pstats import SortKey
results in this error message:
ImportError: cannot import name 'SortKey'
There is a class SortKey(str, Enum)
in this version of pstats
:
https://github.com/python/cpython/blob/master/Lib/pstats.py
However, when I look through local pstats.py
files, I do not have that class, e.g. ~\AppData\Local\Continuum\anaconda3\envs\py36\Lib\pstats.py
is very different than the (cPython) pstats.py
.
I assume I am missing something obvious...
The issue was Python 3.6 vs Python 3.7.
3.6, no SortKey
:
https://docs.python.org/3.6/library/profile.html
3.7, with SortKey
:
https://docs.python.org/3.7/library/profile.html
Using an integer in the docs URL defaults to the latest version, e.g. 3.7, when I needed the docs for 3.6.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With