zoukankan      html  css  js  c++  java
  • TypeError: 'module' object is not callable cp fromhttp://blog.csdn.net/huang9012/article/details/17417133

    程序代码 
    class Person:
         #constructor
         def __init__(self,name,sex):
              self.Name = name
              self.Sex = sex
         def ToString(self):
              return 'Name:'+self.Name+',Sex:'+self.Sex
    在IDLE中报错:
    >>> import Person
    >>> per = Person('dnawo','man')
    Traceback (most recent call last):
      File "<pyshell#2>", line 1, in <module>
        per = Person('dnawo','man')
    TypeError: 'module' object is not callable
    原因分析:
    Python导入模块的方法有两种:import module 和 from module import,区别是前者所有导入的东西使用时需加上模块名的限定,而后者不要。
    正确的代码:
    >>> import Person
    >>> person = Person.Person('dnawo','man')
    >>> print person.Name

    >>> from Person import *
    >>> person = Person('dnawo','man')
    >>> print person.Name

  • 相关阅读:
    canvas粒子时钟
    数组复制
    对象拷贝
    不常见但很有用的chrome调试工具使用方法
    变形transform的副作用
    CSS页面渲染优化属性will-change
    CSS实现导航条Tab切换的三种方法
    CSS两端对齐
    CSS倒影
    CSS滤镜
  • 原文地址:https://www.cnblogs.com/wswang/p/5052279.html
Copyright © 2011-2022 走看看