我的代码是这样引用的:
class Student:
def __init__(self, name, sex):
self.name = name
self.sex= sex
import Student
pig = Student("张三", "男")
正确的应该是:
import Student
pig = Student.Student("张三", "男")
或:
form Student import *
pig = Student("张三", "男")
原因分析:
Python导入模块的方法这两种:
- import module
- from module import
区别在于:
前者使用时需加上模块名限定,即module.xxx。