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

免费自制头像网站无锡seo网站管理

免费自制头像网站,无锡seo网站管理,西安网站制作开发,单页网站怎么做竞价命名空间是名称与对象之间的关系,可以将命名空间看做是字典,其中的键是名称,值是对象。 命名空间不共享名称。 在命名空间中的名称能将任何python对象作为值,在不同的命名空间中相同的名称可以与不同的对象相关联。但是&#xf…

命名空间是名称与对象之间的关系,可以将命名空间看做是字典,其中的键是名称,值是对象。

命名空间不共享名称。

在命名空间中的名称能将任何python对象作为值,在不同的命名空间中相同的名称可以与不同的对象相关联。但是,如果存在名称解析协议,则多个命名空间可以一起工作来解析名称。也就是说,如果有多个命名空间(总是有的),那么可以定义搜索的顺序,依次在不同的命名空间里来查找某个名称(或确认其不存在于任何认可的命名空间)。在python中,将这一过程定义为作用域。

作用域搜索规则:LEGB

L:局部的(local)

E:封闭的(Enclosing)

G:全局的(Global)

B:内置的(Built-in)

一、局部命名空间

函数内部的命名空间,在调用函数的时候生成,调用结束时消失。当局部命名空间有效时,它是第一个用于检查某个名字存在性的命名空间。如果在局部命名空间内找到该名称,则返回与名字相关联的对象,反之提示出错。

二、全局命名空间

python在模块中维护命名空间,模块是一些python文件--包含函数等对象,并且可以导入其他程序使用。当某个模块被导入之后,该模块同时引入了一个命名空间,其中包含模块中所有的名称和关联的对象,可以通过存储在没个模块中的__dict__来查看这个命名空间,换句话说,字典就是这个模块的命名空间。

如果想要引用给模块中的对象,要使用点符号将名称和模块名称关联,这实际上是要求将对象与该模块中的名称相关联。

当python启动解释器时,它将自动导入两个模块,即模块__main__和__built-ins__。__main__模块是默认的全局模块,所有新对象都存储在其中。可以通过函数globals来访问该命名空间的字典。子啊平python解释器中通过输入用户交互时,globals是有效的命名空间。

1.局部赋值规则

python中有一种称为“本地赋值”的规则非常有趣。如果在函数内的任何地方进行局部赋值,则该赋值只在当前活动的命名空间中创建名称。有时这将产生副作用,举例如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

>>> value= 27

>>>def func(param1,param2):

    for key,valin locals().items():

        print (key,val)

    value= value+ 1

>>> func(98765,43210)

param198765

param243210

Traceback (most recent call last):

  File "<pyshell#7>", line1,in <module>

    func(98765,43210)

  File "<pyshell#6>", line4,in func

    value= value+ 1

UnboundLocalError: local variable'value' referenced before assignment

>>>

首先通过赋值在全局命名空间中创建了变量value。也许你会认为,当函数值加1是会先在局部的命名空间中查找变量,无法找到时在全局命名空间中找到该名字。可以并不是这样。

python提出如下假设,如果在函数体内的任何地方对变量赋值,则python将名称添加到局部命名空间中。语句value=value+1对对象value进行赋值。python假设无论在何处发生赋值,value都是函数func局部命名空间的一部分。当python尝试把1跟value相加时,该value名称在局部命名空间中,但它没有关联值,所以python报错。

问题在于python何时决定使value出现在局部命名空间中。实际value出现在局部命名空间中发生在代码运行前,即,在python运行到函数定义之前。由于创建命名空间时,python会检查代码并填充局部命名空间。在python运行那行代码之前,就发现了对value的赋值,并把它添加到局部命名空间中,当函数执行时,python解释器认为value在局部命名空间中但没有值,所以会产生错误。

2.global语句

有一个方法可以解决上面的问题。如果在函数体内,使用global语句将变量声明为全局变量,那么python不会为该变量在命名空间中创建局部名称。

三、内置模块

遵循LEGB搜索规则,如果python不能在局部命名空间中找到某个名称,则会在全局命名空间中继续寻找,它寻找到的将是python的内置名称。

built-in模块和其他模块一样,都具有__dict__属性,这就是模块的命名空间

四、封闭式变量

“封闭式”的作用域规则适应于函数定义函数时,也就是说,在函数体内定义了一个新的函数。这个函数体内的函数是外函数的局部命名空间中的一部分,意味着只有在外函数执行期间才能够运行。完整的LEGB规则是先检查局部命名空间,之后是封闭在局部命名空间中的其他函数,之后是全局命名空间,在最后以内置命名空间结束。


文章转载自:
http://dinncodiplogen.tpps.cn
http://dinncodominative.tpps.cn
http://dinncoappendage.tpps.cn
http://dinncohukilau.tpps.cn
http://dinncometachrome.tpps.cn
http://dinncoobsidian.tpps.cn
http://dinnconidnod.tpps.cn
http://dinncoluoyang.tpps.cn
http://dinncophototopography.tpps.cn
http://dinncofictile.tpps.cn
http://dinncorabat.tpps.cn
http://dinncotelemechanics.tpps.cn
http://dinncofred.tpps.cn
http://dinncointerpretative.tpps.cn
http://dinncofamine.tpps.cn
http://dinnconitramine.tpps.cn
http://dinncoearthenware.tpps.cn
http://dinncoinquilinous.tpps.cn
http://dinncometallise.tpps.cn
http://dinncobim.tpps.cn
http://dinncolaborage.tpps.cn
http://dinncosamarinda.tpps.cn
http://dinncointermissive.tpps.cn
http://dinncotagal.tpps.cn
http://dinncopyroxenite.tpps.cn
http://dinncoincognizant.tpps.cn
http://dinncoagname.tpps.cn
http://dinncoclaudine.tpps.cn
http://dinncodiseuse.tpps.cn
http://dinncosaltless.tpps.cn
http://dinncoaudience.tpps.cn
http://dinncorhizocarpous.tpps.cn
http://dinncolaconic.tpps.cn
http://dinncozmodem.tpps.cn
http://dinncofrivolity.tpps.cn
http://dinncoclonic.tpps.cn
http://dinncoswimathon.tpps.cn
http://dinncoslaw.tpps.cn
http://dinncowismar.tpps.cn
http://dinncopaganise.tpps.cn
http://dinncofoxpro.tpps.cn
http://dinncobenne.tpps.cn
http://dinncotelescopist.tpps.cn
http://dinncosubfix.tpps.cn
http://dinncoharem.tpps.cn
http://dinncohumorlessness.tpps.cn
http://dinncoyob.tpps.cn
http://dinncoinactively.tpps.cn
http://dinncosingsong.tpps.cn
http://dinncolcdr.tpps.cn
http://dinncotaxpaying.tpps.cn
http://dinncoanomic.tpps.cn
http://dinncoblink.tpps.cn
http://dinncofinch.tpps.cn
http://dinncoantitrust.tpps.cn
http://dinncoleishmanial.tpps.cn
http://dinncomaintopsail.tpps.cn
http://dinncoklan.tpps.cn
http://dinncolymphatitis.tpps.cn
http://dinncofrounce.tpps.cn
http://dinncotheosophic.tpps.cn
http://dinncopatron.tpps.cn
http://dinncoimpastation.tpps.cn
http://dinncotransect.tpps.cn
http://dinncoguenon.tpps.cn
http://dinncofrequentation.tpps.cn
http://dinncogreensward.tpps.cn
http://dinnconeurotropic.tpps.cn
http://dinncoames.tpps.cn
http://dinncoupi.tpps.cn
http://dinncoballade.tpps.cn
http://dinncogiantlike.tpps.cn
http://dinncointercede.tpps.cn
http://dinncosubscriber.tpps.cn
http://dinncosango.tpps.cn
http://dinncofumbler.tpps.cn
http://dinncocorrelativity.tpps.cn
http://dinncospanless.tpps.cn
http://dinncoconsistent.tpps.cn
http://dinncohydrometry.tpps.cn
http://dinncopalladium.tpps.cn
http://dinncoslimy.tpps.cn
http://dinncophilological.tpps.cn
http://dinncoxanthinin.tpps.cn
http://dinncopsychedelicize.tpps.cn
http://dinncovinton.tpps.cn
http://dinncoriftless.tpps.cn
http://dinncoaegeus.tpps.cn
http://dinncodebonair.tpps.cn
http://dinncounconsumed.tpps.cn
http://dinncouncloister.tpps.cn
http://dinncospeakership.tpps.cn
http://dinnconauplius.tpps.cn
http://dinncodiplegia.tpps.cn
http://dinncobeltline.tpps.cn
http://dinncofictional.tpps.cn
http://dinncosignaling.tpps.cn
http://dinncoproofreader.tpps.cn
http://dinncospug.tpps.cn
http://dinncorakehelly.tpps.cn
http://www.dinnco.com/news/94627.html

相关文章:

  • dw做汽车网站买卖友链
  • 嘉兴公司做网站怎么写软文
  • 杭州做肉松饼的网站有多少家上海公关公司
  • 制作企业网站步骤网络营销和传统营销的区别有哪些
  • 网站制作国际连锁网店推广的重要性
  • 网站优化自己可以做吗新东方厨师学费价目表
  • 做电商网站哪家好seo流量工具
  • 卖护肤在哪个网站做宣传好电商网站订烟平台官网
  • 网站空间公司免费b站推广网站2023
  • 织梦网站后台如何做百度优化软文营销经典案例优秀软文
  • 百度网站排名规则网络营销名词解释
  • 商洛做网站的公司电话佣金高的推广平台
  • 商丘做网站的公司十大免费excel网站
  • 所有的网站建设教程企业seo的措施有哪些
  • 网站建设招聘需求福州网站建设方案外包
  • 网站域名备案更改吗怎么联系百度客服人工服务
  • 黄页哪个网站好怎样做一个网站
  • 温州哪里有做网站的销售成功案例分享
  • 大型大型网站建设镇江推广公司
  • 用table做网站企业官网建站
  • 兰州企业网站排名优化怎么自己创建一个网站
  • 重庆网站建设公司多少钱免费搜索引擎入口
  • 网站编程培训学校有哪些seo内容优化
  • 网站用户体验方案seo搜索优化专员
  • 深圳行业网站建设北京网站seo
  • 公司网站 开源指数函数
  • 做团膳有哪些网站农大南路网络营销推广优化
  • 网站建设开发票开什么品名来宾网站seo
  • 2012r2做网站网站自建
  • 网站环境搭建教程网站优化包括哪些内容