5 Star 18 Fork 7

xpgo / python-guide

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
imageClass.py 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
xpgo 提交于 2020-08-27 08:24 . init from old files
class Image:
# 这里可以初始化类的属性
def __init__(self, name):
self.name = name
self.link = ""
self.format = "png"
self.width = 600
self.height = 800
self.data = None
# 定义类的函数
def download(self, link):
print("Donwloaded a image from link: " + link)
self.link = link
self.format = "jpg"
self.width = 1000
self.height = 600
def save(self, file_name, file_format):
print("Saving a image to file: " + file_name)
print("The format is : " + file_format)
class ImagePNG(Image):
# 这里可以初始化类的属性
def __init__(self, name):
super().__init__(name)
self.transparency = 0.5
self.format = "png"
# 定义自己的方法
def set_transparency(self, val):
self.transparency = val
# 覆盖父类的方法
def save(self, file_name, file_format):
print("Saveing a PNG image to file : " + file_name)
class ImageJPG(Image):
# 这里可以初始化类的属性
def __init__(self, name):
super().__init__(name)
self.compression = 2
self.format = "jpg"
# 定义自己的方法
def set_compression(self, val):
self.compression = val
# 覆盖父类的方法
def save(self, file_name, file_format):
print("Saveing a JPG image to file : " + file_name)
Python
1
https://gitee.com/xpgo/python-guide.git
git@gitee.com:xpgo/python-guide.git
xpgo
python-guide
python-guide
master

搜索帮助