频道栏目
首页 > 资讯 > Python > 正文

Python学习篇之error

17-09-04        来源:[db:作者]  
收藏   我要投稿

1 No moduled named ...

使用Pycharm ,在一个模块中导入另一个模块的时,出现“No module named ...”的错误

解决方法:找到目标文件所在的文件夹,将其标记为source root

 

2TypeError: 'module' object is not callable

有Person.py模块如下:
class Person:
    def __init__(self,name='未知',sex='未知',age='未知'):
        self.name = name;
        self.sex = sex;
        self.age = age;

    def introduceMyself(self):
        print('My name is ',self.name,". I'm ",self.age,'years old now.')

在Test.py模块中使用Person模块中的Person类:
import Person
person = Person("MrZhang","男",22)
person.introduceMyself();

出现错误:
 
TypeError: 'module' object is not callable
 
原因:
Python导入模块的方法有两种,import module和from module import*,区别是前者导入的东西使用时需要加上模块名进行限定,而后者不需要,直接使用即可。
import Person
person = Person.Person("MrZhang","男",22)
person.introduceMyself();

from Person import*
person = Person("MrZhang","男",22)
person.introduceMyself();
相关TAG标签
上一篇:OSG的渲染树与状态树
下一篇:C#-调用存储过程
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站