可根据需要在程序文件中导入任意数量的类。
dog.py
#!/usr/bin/python
# -- coding: utf-8 --
class DogInfo():
def __init__(self,name,age):
self.name=name
self.age=age
def p_info(self):
print "name:",self.name," age:",self.age
class Dog( ):
def __init__(self,name,age):
self.info=DogInfo(name,age)
def change_name(self,name):
self.info.name=name
def p_info(self):
self.info.p_info()
main.py
# Hello World program in Python
from dog import Dog,DogInfo
dg=Dog("Tom",14)
dg.p_info()
di=DogInfo("Tom",14)
di.p_info()