【解决error】:AttributeError: partially initialized module ‘re‘ has no attribute ‘IGNORECASE‘

困扰了我好久的问题,居然这么轻松就能解决!!!!
代码如下:

from bs4 import BeautifulSoup
import re
import urllib.request
import xlwt
import sqlite3
def askURL(url):
   head = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
    }
    request = urllib.request.Request(url,headers=head)
    try:
        response = urllib.request.urlopen(request)
        html = response.read().decode("utf-8")
        print(html)

报错:AttributeError: partially initialized module ‘re’ has no attribute ‘IGNORECASE’

在论坛看到一个同样的问题,如果有文件包中有以re.py命名的python文件,则python可能就会查看其中的内容,而不会直接导入标准的re库

看完马上检查我的python练习文件包,似确实有一个re.py文件,罪魁祸首就是它,我立马重新命名了它,程序就可以运行了!!开心!

你可能感兴趣的:(报错,python)