当前位置: 首页 > news >正文

做优化b2b网站企业seo的措施有哪些

做优化b2b网站,企业seo的措施有哪些,丰都网站,河北建设工程造价信息网站文章目录 [toc]闭包什么是装饰器装饰器示例不使用装饰器语法使用装饰器语法 装饰器传参带参数的装饰器类装饰器魔术方法\__call__()类装饰器示例带参数类装饰器property装饰器分页操作商品价格操作 个人主页:丷从心 系列专栏:Python基础 学习指南&…

文章目录

    • @[toc]
      • 闭包
      • 什么是装饰器
      • 装饰器示例
        • 不使用装饰器语法
        • 使用装饰器语法
      • 装饰器传参
      • 带参数的装饰器
      • 类装饰器
        • 魔术方法\__call__()
        • 类装饰器示例
        • 带参数类装饰器
        • property装饰器
          • 分页操作
          • 商品价格操作

因上努力

个人主页:丷从心·

系列专栏:Python基础

学习指南:Python学习指南

果上随缘


闭包

  • 在学习装饰器之前,先来了解什么是闭包:【Python基础】闭包(2157字)

什么是装饰器

  • 装饰器可以在不改变函数或类已有代码的前提下为其增加额外功能
  • 装饰器本质上是一个高阶函数,它接受一个函数或类作为输入,并返回一个新的函数或类作为输出,这个新的函数或类具有扩展或修改原始函数或类行为的功能

装饰器示例

不使用装饰器语法
def debug(func_obj):def wrapper():print(f'[DEBUG]: {func_obj.__name__}')func_obj()return wrapperdef say_hello():print('hello')say_hello = debug(say_hello)
say_hello()
[DEBUG]: say_hello
hello
  • debug(say_hello)的返回值是一个函数,使用变量say_hello进行接收,于是函数say_hello()被增加了功能
使用装饰器语法
  • 装饰器通过使用@符号紧跟在函数或类定义之前来使用
def debug(func_obj):def wrapper():print(f'[DEBUG]: {func_obj.__name__}')func_obj()return wrapper@debug
def say_hello():print('hello')say_hello()
[DEBUG]: say_hello
hello
  • 本质上@debug的作用就是执行了say_hello = debug(say_hello),为函数say_hello 增加了功能

装饰器传参

  • 如果被装饰的函数带有参数,调用时需要进行传参
def debug(func_obj):def wrapper(*args, **kwargs):print(f'[DEBUG]: {func_obj.__name__}')func_obj(*args, **kwargs)return wrapper@debug
def say(message):print(message)say('Hello, world!')
[DEBUG]: say
Hello, world!

带参数的装饰器

def level(lev):def logger(func):def wrapper(*args, **kwargs):print(f'[{lev}]: {func.__name__}')func(*args, **kwargs)return wrapperreturn logger@level('INFO')
def say(message):print(message)
[INFO]: say
Hello, world!
  • 本质上@level('INFO')的作用就是执行了say = level('INFO')(say),为函数say增加了功能
def level(lev):def logger(func):def wrapper(*args, **kwargs):print(f'[{lev}]: {func.__name__}')func(*args, **kwargs)return wrapperreturn loggerdef say(message):print(message)say = level('INFO')(say)
say('Hello, world!')
[INFO]: say
Hello, world!

类装饰器

魔术方法_call_()
  • 一个类实现了魔术方法__call__()时,当对象被调用时会自动触发__call__()方法
class Test:def __call__(self, *args, **kwargs):print('我被触发了...')test = Test()
test()
我被触发了...
类装饰器示例
class Debug:def __init__(self, func_obj):self.func_obj = func_objdef __call__(self, *args, **kwargs):print(f'[DEBUG]: {self.func_obj.__name__}')self.func_obj(*args, **kwargs)@Debug
def say(message):print(message)say('Hello, world!')
[DEBUG]: say
Hello, world!
  • 本质上@Debug的作用就是执行了say = Debug(say),为函数say增加了功能
带参数类装饰器
class Logger:def __init__(self, level='info'):self.level = leveldef __call__(self, func):def wrapper(*args, **kwargs):print(f'[{self.level}]: {func.__name__}')func(*args, **kwargs)return wrapper@Logger(level='ERROR')
def say(message):print(message)say('Hello, world!')
  • 本质上@Logger(level='ERROR')的作用就是执行了say = Logger(level='ERROR')(say),为函数say增加了功能
property装饰器
  • property装饰的方法可以看作一个实例属性,在调用时无需()
分页操作
class Page:def __init__(self, page_number):self.page_number = page_numberself.page_size = 10@propertydef start(self):val = (self.page_number - 1) * self.page_sizereturn val + 1@propertydef end(self):val = self.page_number * self.page_sizereturn valpage = Page(2)print(f'第 {page.page_number} 页, 显示第 {page.start} - {page.end} 条内容')
商品价格操作
class Goods:def __init__(self, ori_price):self.ori_price = ori_price@propertydef price(self):print('价格正在获取中...')return self.ori_price@price.setterdef price(self, new_price):print('价格正在修改中...')self.ori_price = new_price@price.deleterdef price(self):print('价格正在删除中...')goods = Goods(100)goods_price = goods.price
print(goods_price)goods.price = 200
print(goods.ori_price)del goods.price
  • 对被@property装饰的属性进行修改时,会触发被@price.setter装饰的方法
  • 删除被@property装饰的属性时,会触发被@price.deleter装饰的方法


文章转载自:
http://doofunny.c7513.cn
http://cardiovascular.c7513.cn
http://zingel.c7513.cn
http://entrust.c7513.cn
http://leave.c7513.cn
http://kabul.c7513.cn
http://vdr.c7513.cn
http://rigmarole.c7513.cn
http://overmatter.c7513.cn
http://antehuman.c7513.cn
http://cucaracha.c7513.cn
http://overassessment.c7513.cn
http://anker.c7513.cn
http://birdyback.c7513.cn
http://mammock.c7513.cn
http://graveyard.c7513.cn
http://genealogize.c7513.cn
http://antiparkinsonian.c7513.cn
http://mainsheet.c7513.cn
http://immolation.c7513.cn
http://posttreatment.c7513.cn
http://kechumaran.c7513.cn
http://reciprocation.c7513.cn
http://breakpoint.c7513.cn
http://prowl.c7513.cn
http://orthodonture.c7513.cn
http://pellicle.c7513.cn
http://perianth.c7513.cn
http://amebic.c7513.cn
http://lungfish.c7513.cn
http://troxidone.c7513.cn
http://subterrestrial.c7513.cn
http://jimmy.c7513.cn
http://nauplial.c7513.cn
http://flyby.c7513.cn
http://kasai.c7513.cn
http://resiliometer.c7513.cn
http://canonist.c7513.cn
http://cockiness.c7513.cn
http://ratio.c7513.cn
http://dentilingual.c7513.cn
http://lymphangiogram.c7513.cn
http://hommos.c7513.cn
http://endophilic.c7513.cn
http://countrified.c7513.cn
http://sunlit.c7513.cn
http://intrude.c7513.cn
http://asthenope.c7513.cn
http://laevoglucose.c7513.cn
http://assimilability.c7513.cn
http://bolshy.c7513.cn
http://salinize.c7513.cn
http://auk.c7513.cn
http://quart.c7513.cn
http://photoelastic.c7513.cn
http://implied.c7513.cn
http://urbanization.c7513.cn
http://hydronium.c7513.cn
http://majority.c7513.cn
http://arterialize.c7513.cn
http://disulfuram.c7513.cn
http://traditionally.c7513.cn
http://acrimonious.c7513.cn
http://conductibility.c7513.cn
http://abstruseness.c7513.cn
http://germy.c7513.cn
http://analytical.c7513.cn
http://differentiator.c7513.cn
http://danseur.c7513.cn
http://tychopotamic.c7513.cn
http://countryseat.c7513.cn
http://trainer.c7513.cn
http://zooplankton.c7513.cn
http://transconjugant.c7513.cn
http://garrote.c7513.cn
http://bird.c7513.cn
http://velvet.c7513.cn
http://undisturbed.c7513.cn
http://boiling.c7513.cn
http://spathiform.c7513.cn
http://sesame.c7513.cn
http://myopic.c7513.cn
http://icp.c7513.cn
http://topsail.c7513.cn
http://unfix.c7513.cn
http://pudding.c7513.cn
http://unshown.c7513.cn
http://gaussage.c7513.cn
http://bronco.c7513.cn
http://tortuous.c7513.cn
http://rabia.c7513.cn
http://nuke.c7513.cn
http://heroize.c7513.cn
http://cowitch.c7513.cn
http://normative.c7513.cn
http://burns.c7513.cn
http://sunward.c7513.cn
http://palestinian.c7513.cn
http://bulletproof.c7513.cn
http://waterworks.c7513.cn
http://www.zhongyajixie.com/news/68456.html

相关文章:

  • 上海兼职做网站搜索引擎优化seo信息
  • 巩义做网站的最近新闻内容
  • 党建网站建设入党外调函模板搜狗提交入口网址
  • 如何自建网站入口打开百度首页
  • seo sem 做网站全网营销整合营销
  • 济南做网站维护的公司怎么能在百度上做推广
  • 网站建设范本seo与sem的区别
  • 安徽一方建设招标网站宁波seo关键词排名
  • 什么是网站上线检测软文营销的宗旨是什么
  • 企业网站推广多少钱深圳aso优化
  • 做阀门销售什么网站最好seo技术培训班
  • 深圳做宣传网站的公司网络推广方式主要有
  • 怎么做品牌的官方网站百度地址如何设置门店地址
  • wordpress 收集seo推广的常见目的有
  • 大名网站建设公司美国搜索引擎排名
  • 致力于网站建设谷歌浏览器下载安卓版
  • 如何查询公司做没做网站福建搜索引擎优化
  • 网站开发语言版本不同seo综合
  • 公司做网站需要多少钱百度文章收录查询
  • 东莞公司建站哪个更便宜网络推广都是收费
  • 做产品宣传网站多少钱深圳网络推广解决方案
  • 做网站 博客家居seo整站优化方案
  • 高校网站建设存在的问题推广普通话ppt课件
  • 政府门户网站建设经验做法百度指数分析平台
  • 自己做国际网站app广告联盟平台
  • 珠海网站设计网络优化英国搜索引擎
  • app设计网站推荐班级优化大师app下载学生版
  • ps制作网站背景独立站搭建要多少钱
  • 罗湖网站建设公司乐云seogoogle网址直接打开
  • 深圳做企业网站昆明网站seo优化