module Student
とclass を混同していますStudent
。例えば:
>>> import Student
>>> Student("Joe", 2, 3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
モジュールであるため、これは理にかなっています。
>>> Student
<module 'Student' from './Student.py'>
モジュール内のクラスを取得するには、次のobjectname.membername
構文を使用します。
>>> Student.Student
<class 'Student.Student'>
>>> Student.Student("Joe", 2, 3)
<Student.Student object at 0xb6f9f78c>
>>> print(Student.Student("Joe", 2, 3))
Joe is in year 2, with a GPA of 3.
または、クラスを直接インポートできます。
>>> from Student import Student
>>> Student
<class 'Student.Student'>
>>> print(Student("Joe", 2, 3))
Joe is in year 2, with a GPA of 3.