源码片段:

class myThread(threading.Thread):
def __init__(self, threadID, name, counter):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.counter = counter

执行时提示如下错误:

Traceback (most recent call last):

File "threading.py", line 2, in <module>

import threading

File "I:\MY_TEST\py\thread\threading.py", line 7, in <module>

class myThread(threading.Thread):

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

1、检查是否为threading和Thread拼写错误,认真对比后确认无误;
2、判断是否为threading模块没有安装,查询发现python3.4自带就有此模块;
3、最后检查脚本的名称是threading.py,怀疑是与模块名称冲突,导致加载错误,将脚本名称改为thread_ing.py后执行,正确


由此引出两个问题:

1、命名问题:不管是变量还是脚本名称,都不要和python本身的模块、关键字等重合;

2、Python加载模块顺序问题:

加载模块搜索路径被存储在sys模块中的path变量中,我们使用sys.path输出:

第一个参数是‘’(空串),代表是当前目录,后续的目录分别为PYTHONPATH目录和标准库目录,所以得到加载模块的顺序为:

1)当前主目录

2)PYTHONPATH目录

3)标准库目录

'module' object has no attribute 'Thread'解决方法及模块加载顺序的更多相关文章

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

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

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

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

  3. Python基础学习-'module' object has no attribute 'urlopen'解决方法

    import numpy as npimport urlliburl = "http://archive.ics.uci.edu/ml/machine-learning-databases/ ...

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

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

  5. AttributeError: 'module' object has no attribute 'Thread'

    $ python thread.py starting at: 2015-08-05 00:24:24Traceback (most recent call last):  File "th ...

  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. pygame模块使用时出现AttributeError: module ‘pygame’ has no attribute '…'错误解决方法

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

  9. 如何解决requireJs的模块加载超时

    requireJs的加载是一种异步机制,它加载js的时候有个默认的超时机制,当加载一个js超过一定时间的时候,它就会在浏览器中抛出模块加载超时错误,接下来,就不会加载这个模块. 这个机制其实是起到了节 ...

随机推荐

  1. Oracle数据库查询优化方案(处理上百万级记录如何提高处理查询速度)

    1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引.2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索引 ...

  2. linux简单内核链表排序

    #include <stdio.h> #include <stdlib.h> #define container_of(ptr, type, mem)(type *)((uns ...

  3. DOM元素的Attribute(特性)和Property(属性) 【转载】

    1.介绍: 上篇js便签笔记http://www.cnblogs.com/wangfupeng1988/p/3626300.html最后提到了dom元素的Attribute和Property,本文简单 ...

  4. Javascript中没有块级作用域(模仿)

    在C/C++中,由花括号封闭的代码块都有自己的作用域,也就是块级作用域(私有作用域).而在javascript中则没有块级作用域,首先来看一段代码: function test(){ for(var ...

  5. Oracle中的instr()函数

    一.instr()函数 1.语法:instr(sourceString,destString,start,appearPosition) sourceString代表源字符串; destString代 ...

  6. JSON 的小技巧

    有的时候上游传过来的字段是string类型的,但是我们却想用变成数字来使用. 本来用一个json:",string" 就可以支持了,如果不知道golang的这些小技巧,就要大费周章 ...

  7. BZOJ_5055_膜法师_树状数组+离散化

    BZOJ_5055_膜法师_树状数组+离散化 Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然 ...

  8. [Usaco2005 nov]Grazing on the Run 边跑边吃草 BZOJ1742

    分析: 首先,连续选择一段必定最优... 区间DP,f[i][j]表示从i开始,连续j个被吃掉了,并且,牛在i处,g[i][j]则表示在i+j-1处 f[i][j]可以从g[i+1][j]和f[i+1 ...

  9. PCB设计检查

    一.资料输入阶段1.在流程上接收到的资料是否齐全(包括:原理图.*.brd文件.料单.PCB设计说明以及PCB设计或更改要求.标准化要求说明.工艺设计说明文件)2.确认PCB模板是最新的3. 确认模板 ...

  10. SAP S4系统创建Customer和Vendor的BAPI

    对应的BAPI是:RFC_CVI_EI_INBOUND_MAIN SAP 又调皮了,又不安常理出牌!