模块“re"没有属性“findall" [英] module 're' has no attribute 'findall'

查看:70
本文介绍了模块“re"没有属性“findall"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下 python 模块:

I am trying to use the following python module:

import re
test = 'some text'
find = re.findall(r'text', test)
print(find)

当我尝试在 sublime 中运行它时,它写道:

When i try to run it in sublime, it writes:

AttributeError: module 're' has no attribute 'findall'

如果我尝试在 Cygwin 中运行它,则会出现一条消息:

If i try to run it in Cygwin, there is a message:

AttributeError: 'module' object has no attribute 'findall'

但是如果我在 python 控制台中使用属性findall",它可以正常工作.我真的不明白,怎么了.我记得在 Sublime 中我使用 python 3.5.1,cygwin 使用 python 3.4.3.

But if i use attibute "findall" in python console, it works without any problem. I really don't undestand, what's wrong. In Sublime i use python 3.5.1, cygwin uses python 3.4.3, as i remember.

推荐答案

如果您有一个名为 re.py 的文件,那么当您尝试 import re 时,Python可以查看该文件内部而不是标准模块 re 内部.所以不要将文件命名为 re.py(或您想导入的任何其他模块的名称).

If you have a file called re.py, then when you try and import re, Python may look inside that file instead of inside the standard module re. So don't name a file re.py (or the name of any other module you want to import).

这篇关于模块“re"没有属性“findall"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆