我正在尝试处理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")')
根据文档,这执行起来没有问题。
然而,
import pstats
from pstats import SortKey
导致此错误消息:
ImportError: cannot import name 'SortKey'
此版本的pstats
中有一个class SortKey(str, Enum)
:https://github.com/python/cpython/blob/master/Lib/pstats.py
然而,当我查看本地pstats.py
文件时,我没有该类,例如~AppDataLocalContinuumanaconda3envspy36Libpstats.py
与(cPython(pstats.py
非常不同。
我想我错过了一些显而易见的东西。。。
问题是Python 3.6与Python 3.7。
3.6,无SortKey
:https://docs.python.org/3.6/library/profile.html
3.7,带有SortKey
:https://docs.python.org/3.7/library/profile.html
在文档URL中使用整数默认为最新版本,例如3.7,当我需要3.6的文档时。