Python(c)配置文件:从pstats导入SortKey时出错

Eva*_*van 5 python-3.x

我正在尝试通过Python的个人资料(rs)的文档。我在Win10笔记本电脑上的Anaconda中使用Python 3.6。

https://docs.python.org/3/library/profile.html

import cProfile
import re
cProfile.run('re.compile("foo|bar")')
Run Code Online (Sandbox Code Playgroud)

根据文档,这没有问题。

然而,

import pstats
from pstats import SortKey
Run Code Online (Sandbox Code Playgroud)

导致此错误消息:

ImportError: cannot import name 'SortKey'
Run Code Online (Sandbox Code Playgroud)

class SortKey(str, Enum)此版本的中有一个pstatshttps : //github.com/python/cpython/blob/master/Lib/pstats.py

但是,当我浏览本地pstats.py文件时,我没有该类,例如,~\AppData\Local\Continuum\anaconda3\envs\py36\Lib\pstats.py它与(cPython)完全不同pstats.py

我想我缺少明显的东西...

Eva*_*van 13

问题是Python 3.6与Python 3.7。

3.6,否SortKeyhttps : //docs.python.org/3.6/library/profile.html

3.7,带有SortKeyhttps : //docs.python.org/3.7/library/profile.html

当我需要3.6文档时,在文档URL中使用整数默认为最新版本,例如3.7。