#codeing:utf-8
#! /usr/bin/python
#coding:utf-8
class Student(object):
def __init__(self, name, score):
self.name = name
self.score = score
第一次運(yùn)行的python程序,
>>> import Student
>>> student = Student("michael", 99)
發(fā)生了錯(cuò)誤,
raceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
原因是python的import語法,在使用時(shí)需要加上模塊名限定才能正確調(diào)用,
>>> student = Student.Student("michael", 99)
>>> student.name
'michael'
如果不想加上模塊名,可以這么導(dǎo)入
>>> from Student import Student
>>> student = Student("michael", 98)
>>> student.name
'michael'
>>> student.score
98