因此,我有一个包含一个类的学生包,在该包之外有一个main.py,我正在尝试创建一个学生示例对象
class Student:
Id=""
def __init__(self, Id):
self.Id = Id单独的文件main.py:
def main():
print("is workign")
temp = Student("50") ## I want to create the object of class Student and send an attribute
if __name__ == '__main__':
main()任何帮助都将不胜感激。
发布于 2013-10-13 13:11:51
虽然类是在代码外部定义的,但需要导入该类。假设main.py和student.py在同一个文件夹中:
student.py
class Student:
Id=""
def __init__(self, Id):
self.Id = Idmain.py
def main():
from student import Student
print("is workign")
temp = Student("50") ## I want to create the object of class Student and send an attribute
if __name__ == '__main__':
main()https://stackoverflow.com/questions/19342034
复制相似问题