import numpy as np
import urllib url = "http://archive.ics.uci.edu/ml/machine-learning-databases/pima-indians-diabetes/pima-indians-diabetes.data"
# 下载网络数据
raw_data = urllib.urlopen(url)
# 处理网络下载的数据为矩阵,方便后面的数据操作
dataset = np.loadtxt(raw_data, delimiter=",")
# 提取特征矩阵数据,dataset中的所有行,所有0-7列的数据都保存在X中
X = dataset[:,0:7]
# 提取目标变量数据,dataset中的所有行,所有8列的数据都保存在y中
y = dataset[:,8]

运行程序会报错module 'urllib' has no attribute 'urlopen'

原因是Python3里的urllib模块已经发生改变,此处的urllib都应该改成urllib.request。
 
import numpy as np
import urllib.request url = "http://archive.ics.uci.edu/ml/machine-learning-databases/pima-indians-diabetes/pima-indians-diabetes.data"
# 下载网络数据
raw_data = urllib.request.urlopen(url)
# 处理网络下载的数据为矩阵,方便后面的数据操作
dataset = np.loadtxt(raw_data, delimiter=",")
# 提取特征矩阵数据,dataset中的所有行,所有0-7列的数据都保存在X中
X = dataset[:,0:7]
# 提取目标变量数据,dataset中的所有行,所有8列的数据都保存在y中
y = dataset[:,8]

Python基础学习-'module' object has no attribute 'urlopen'解决方法的更多相关文章

  1. Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

    最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...

  2. 'module' object has no attribute 'Thread'解决方法及模块加载顺序

    源码片段: class myThread(threading.Thread): def __init__(self, threadID, name, counter): threading.Threa ...

  3. 提示AttributeError: 'module' object has no attribute 'HTTPSHandler'解决方法

    今天在新机器上安装sqlmap,运行提示AttributeError: 'module' object has no attribute 'HTTPSHandler' 网上找了找资料,发现一篇文章ht ...

  4. python中引入包的时候报错AttributeError: module 'sys' has no attribute 'setdefaultencoding'解决方法?

    python中引入包的时候报错:import unittestimport smtplibimport timeimport osimport sysimp.reload(sys)sys.setdef ...

  5. pygame模块使用时出现AttributeError: module ‘pygame’ has no attribute '…'错误解决方法

    pygame模块使用时出现AttributeError: module 'pygame' has no attribute '-'错误解决方法 首先在pygame中存在init()模块,出现这样的问题 ...

  6. 【pycharm】pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法

    pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法 解决方法: 在pycharm的安装目 ...

  7. [开发技巧]·AttributeError: module 'pywt' has no attribute 'wavedec'解决方法

    [开发技巧]·AttributeError: module 'pywt' has no attribute 'wavedec'解决方法 1.卸载 pywt pip uninstall pywt 2.安 ...

  8. AttributeError: module '__main__' has no attribute 'main'解决方法

    在终端运行.py文件时报错:AttributeError: module '__main__' has no attribute 'main' 原因:在PyCharm里运行python程序需要添加 i ...

  9. python 错误AttributeError: 'module' object has no attribute 'AF_INET'

    写了一个简单的python socket的程序.运行时,报错如下 原因:文件的命名与Python的function的命名冲突 修改名称后,发现还是无法运行,检查目录下面是否有 这样子的一个文件,删除即 ...

随机推荐

  1. JQuery-基础学习1

    1)JQuery语法 jquery语法是为HTML元素的选取编制,可以对元素执行某些操作. 基础语法是:$(selector).action() 美元符号定义JQuery 选择符(selector)& ...

  2. Windows删除文件时找不到该项目

    当在Windows删除文件时出现找不到该项目或者显示该文件不在磁盘中,可以尝试以下方法: 在要删除文件的同级目录下 新建一文本文档,将下列代码复制到文档中,将文档保存为后缀名为.bat的文档(名字随意 ...

  3. WebService调用(基于KSOAP2)

    public static boolean getData(String param) { //WebService服务器地址 String SERVICE_URL = "http://22 ...

  4. vi 编辑器笔记

    摘要: vi从安装到使用 vi从菜鸟到高手 0. vim - Vi IMproved, a programmers text editor 分为 VI和VIM,现在流行的发行版里面VI=VIM 是一个 ...

  5. 对Spring事务的一些误解

    提起spring事务,就会让人联想起四大基本特征,五个隔离级别,七大传播特性.相信大多数人都知道这些东西,但是知道是一回事情,能用好真的是另一回事了.在使用Spring事务的时候,我曾遇到过几个比较严 ...

  6. 项目swift的一些问题

    在用swift做项目的时候,总会把之前oc的思想转过来. 1. 对Alamofire的再次封装,之前使用AFNetwork进行了在次封装,这样做的好处就是可以用一个全局的类来管理全部的网络请求,这样就 ...

  7. sqoop1.4.6配置安装

    1.下载sqoop1.4.6 2.配置环境变量. 3.复制sqoop/conf/sqoop-env-template.sh为sqoop-env.sh 添加相关的配置 #Setpath to where ...

  8. RxSwift 对 MJRefresh 使用的封装

    对于一个很常用的两个库, MJRefresh 如何可以像 UIButton 使用方式呢: btn.rx.tap.subscribe(...) Rxswift 中的很多类似处理的方式都使用了跟下面极为相 ...

  9. Leetcode题解(23)

    69. Sqrt(x) 题目 分析,题目实现求一个int数的平方根,最暴力的算法就是逐个遍历,从1开始到x,判断是否有一个数i,其中满足i*i<=x,并且(i+1)*(i+1)>x;这个算 ...

  10. Lifting the Stone(求多边形的重心—)

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...