Python:“ Tkinter”模块中包含“ re”模块吗?

时间:2018-07-15 12:12:58

标签: python python-3.x tkinter conda miniconda

我在 MacOS 上将 Python 3.6.4 Miniconda 一起使用。我很好奇,在导入re之后可以使用属于tkinter模块的方法。例如,如果我想使用re方法而不导入它:

>>> re.compile('abc')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 're' is not defined

但是,如果我在导入re之后使用tkinter方法,它将正常工作,例如:

>>> from tkinter import *
>>> re.compile('abc')
re.compile('abc')

因此,即使我没有re.compile(),也可以使用import re。为什么会发生?

1 个答案:

答案 0 :(得分:1)

the tkinter Source第39行开始:

import re

因此,当您导入Module tkinter时,会自动使用它导入re