Typeerror: 'module' object is not callable Cause Analysis
Source: Internet
Author: User
Program code
Class person:
# Constructor
Def _ init _ (self, name, sex ):
Self. Name = Name
Self. Sex = sex
Def tostring (Self ):
Return 'name: '+ self. Name +', sex: '+ self. Sex
Error in idle:
>>> Import person
>>> Per = person ('dnaw', 'man ')
Traceback (most recent call last ):
File "<pyshell #2>", line 1, in <module>
Per = person ('dnaw', 'man ')
Typeerror: 'module' object is not callable
Cause analysis: There are two ways to import a python module: import module and from module import. The difference is that the restrictions on the module name must be added to all the imported items in the former, while the latter does not. Correct code:
>>> Import person
>>> Person = person. Person ('dna wo', 'Man ')
>>> Print person. Name
Or
>>> From person import *
>>> Person = person ('dnaw', 'man ')
>>> Print person. Name
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.