pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <legend id='4G8Pv'><style id='4G8Pv'><dir id='4G8Pv'><q id='4G8Pv'></q></dir></style></legend>
    <tfoot id='4G8Pv'></tfoot>

      <small id='4G8Pv'></small><noframes id='4G8Pv'>

        <bdo id='4G8Pv'></bdo><ul id='4G8Pv'></ul>

      1. <i id='4G8Pv'><tr id='4G8Pv'><dt id='4G8Pv'><q id='4G8Pv'><span id='4G8Pv'><b id='4G8Pv'><form id='4G8Pv'><ins id='4G8Pv'></ins><ul id='4G8Pv'></ul><sub id='4G8Pv'></sub></form><legend id='4G8Pv'></legend><bdo id='4G8Pv'><pre id='4G8Pv'><center id='4G8Pv'></center></pre></bdo></b><th id='4G8Pv'></th></span></q></dt></tr></i><div class="hh2377p" id='4G8Pv'><tfoot id='4G8Pv'></tfoot><dl id='4G8Pv'><fieldset id='4G8Pv'></fieldset></dl></div>
      2. 未綁定的變量和名稱

        Unbound variable and name(未綁定的變量和名稱)
      3. <small id='gH4Pk'></small><noframes id='gH4Pk'>

        <legend id='gH4Pk'><style id='gH4Pk'><dir id='gH4Pk'><q id='gH4Pk'></q></dir></style></legend>

          <tfoot id='gH4Pk'></tfoot>
          <i id='gH4Pk'><tr id='gH4Pk'><dt id='gH4Pk'><q id='gH4Pk'><span id='gH4Pk'><b id='gH4Pk'><form id='gH4Pk'><ins id='gH4Pk'></ins><ul id='gH4Pk'></ul><sub id='gH4Pk'></sub></form><legend id='gH4Pk'></legend><bdo id='gH4Pk'><pre id='gH4Pk'><center id='gH4Pk'></center></pre></bdo></b><th id='gH4Pk'></th></span></q></dt></tr></i><div class="r8njw38" id='gH4Pk'><tfoot id='gH4Pk'></tfoot><dl id='gH4Pk'><fieldset id='gH4Pk'></fieldset></dl></div>
              <tbody id='gH4Pk'></tbody>

                • <bdo id='gH4Pk'></bdo><ul id='gH4Pk'></ul>

                  本文介紹了未綁定的變量和名稱的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  根據python參考手冊我們有

                  當根本找不到名稱時,會引發 NameError 異常.如果該名稱指的是尚未綁定的局部變量,a引發 UnboundLocalError 異常.UnboundLocalError 是一個子類的名稱錯誤.

                  When a name is not found at all, a NameError exception is raised. If the name refers to a local variable that has not been bound, a UnboundLocalError exception is raised. UnboundLocalError is a subclass of NameError.

                  我不明白什么時候拋出 UnboundLocalError?因為

                  I don't to understand when the UnboundLocalError is thrown? Because

                  Python 缺少聲明并允許發生名稱綁定操作代碼塊內的任何位置.

                  Python lacks declarations and allows name binding operations to occur anywhere within a code block.

                  那么我們怎樣才能聲明一個變量,而不是初始化她呢?

                  So how we can declare a variable, but not to initialize her?

                  推薦答案

                  你可以引用一個沒有分配的名字:

                  You can refer to a name without having assigned to it:

                  >>> foobar
                  Traceback (most recent call last):
                    File "<stdin>", line 1, in <module>
                  NameError: name 'foobar' is not defined
                  

                  這里 foobar 被引用,但從未被分配到.這會引發 NameError 因為名稱從未綁定.

                  Here foobar is being referred to, but was never assigned to. This raises a NameError because the name was never bound.

                  更微妙的是,這里沒有發生分配,因為執行的行永遠不會運行:

                  More subtly, here assignment is not happening because the line that does is never run:

                  >>> def foo():
                  ...     if False:
                  ...         spam = 'eggs'
                  ...     print spam
                  ... 
                  >>> foo()
                  Traceback (most recent call last):
                    File "<stdin>", line 1, in <module>
                    File "<stdin>", line 4, in foo
                  UnboundLocalError: local variable 'spam' referenced before assignment
                  

                  因為 spam = 'eggs' 永遠不會執行,所以 print spam 會引發 UnboudLocalError.

                  Because spam = 'eggs' is never executed, print spam raises an UnboudLocalError.

                  請注意,Python 中沒有任何地方聲明過.您綁定或不綁定,聲明不是語言的一部分.

                  Note that nowhere in Python is a name ever declared. You bind or don't bind, declaration is not part of the language.

                  相反,binding 用于確定名稱的范圍;綁定操作包括賦值、用于 for 循環的名稱、函數參數、導入語句、在 except 子句中保存捕獲的異常的名稱、上下文管理器的名稱一個 with 語句所有的綁定名稱.

                  Instead, binding is used to determine the scope of a name; binding operations include assignment, names used for a for loop, function parameters, import statements, name to hold a caught exception in an except clause, the name for a context manager in a with statement all bind names.

                  如果名稱綁定在范圍內(例如在函數中),則它是本地名稱,除非您使用 global 語句(或 nonlocal 語句在 Python 3 中)將名稱顯式標記為全局(或閉包).

                  If a name is bound in a scope (such as in a function) then it is a local name, unless you use a global statement (or a nonlocal statement in Python 3) to explicitly mark the name as a global (or a closure) instead.

                  所以下面是一個錯誤:

                  >>> foo = None
                  >>> def bar():
                  ...     if False:
                  ...         foo = 'spam'
                  ...     print foo
                  ... 
                  >>> bar()
                  Traceback (most recent call last):
                    File "<stdin>", line 1, in <module>
                    File "<stdin>", line 4, in bar
                  UnboundLocalError: local variable 'foo' referenced before assignment
                  

                  因為 foosomewhere 綁定在 bar 函數范圍內.但是如果您將 foo 標記為全局,則該函數可以工作:

                  because foo is being bound somewhere in the bar function scope. But if you mark foo as a global, the function works:

                  >>> foo = None
                  >>> def bar():
                  ...     global foo
                  ...     if False:
                  ...         foo = 'spam'
                  ...     print foo
                  ... 
                  >>> bar()
                  None
                  

                  因為現在 Python 編譯器知道您希望 foo 改為全局變量.

                  because now the Python compiler knows you wanted foo to be a global instead.

                  所有這些都記錄在 命名和綁定部分 Python 參考文檔.

                  This is all documented in the Naming and Binding section of the Python reference documentation.

                  這篇關于未綁定的變量和名稱的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)
                  Configuring Python to use additional locations for site-packages(配置 Python 以使用站點包的其他位置)
                  How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造python包)
                  Install python packages on OpenShift(在 OpenShift 上安裝 python 包)
                  How to refresh sys.path?(如何刷新 sys.path?)
                  Distribute a Python package with a compiled dynamic shared library(分發帶有已編譯動態共享庫的 Python 包)
                    <tbody id='DL2bp'></tbody>

                • <legend id='DL2bp'><style id='DL2bp'><dir id='DL2bp'><q id='DL2bp'></q></dir></style></legend>
                    <bdo id='DL2bp'></bdo><ul id='DL2bp'></ul>
                    <i id='DL2bp'><tr id='DL2bp'><dt id='DL2bp'><q id='DL2bp'><span id='DL2bp'><b id='DL2bp'><form id='DL2bp'><ins id='DL2bp'></ins><ul id='DL2bp'></ul><sub id='DL2bp'></sub></form><legend id='DL2bp'></legend><bdo id='DL2bp'><pre id='DL2bp'><center id='DL2bp'></center></pre></bdo></b><th id='DL2bp'></th></span></q></dt></tr></i><div class="bfmhzjd" id='DL2bp'><tfoot id='DL2bp'></tfoot><dl id='DL2bp'><fieldset id='DL2bp'></fieldset></dl></div>
                        • <small id='DL2bp'></small><noframes id='DL2bp'>

                            <tfoot id='DL2bp'></tfoot>
                            主站蜘蛛池模板: PTFE接头|聚四氟乙烯螺丝|阀门|薄膜|消解罐|聚四氟乙烯球-嘉兴市方圆氟塑制品有限公司 | 海鲜池-专注海鲜鱼缸、移动海鲜缸、饭店鱼缸设计定做-日晟水族厂家 | 北京自然绿环境科技发展有限公司专业生产【洗车机_加油站洗车机-全自动洗车机】 | WF2户外三防照明配电箱-BXD8050防爆防腐配电箱-浙江沃川防爆电气有限公司 | COD分析仪|氨氮分析仪|总磷分析仪|总氮分析仪-圣湖Greatlake | TPU薄膜_TPU薄膜生产厂家_TPU热熔胶膜厂家定制_鑫亘环保科技(深圳)有限公司 | 杭州标识标牌|文化墙|展厅|导视|户内外广告|发光字|灯箱|铭阳制作公司 - 杭州标识标牌|文化墙|展厅|导视|户内外广告|发光字|灯箱|铭阳制作公司 | 工业铝型材生产厂家_铝合金型材配件批发精加工定制厂商 - 上海岐易铝业 | 上海平衡机-单面卧式动平衡机-万向节动平衡机-圈带动平衡机厂家-上海申岢动平衡机制造有限公司 | 刑事律师_深圳著名刑事辩护律师_王平聚【清华博士|刑法教授】 | 仓储笼_金属箱租赁_循环包装_铁网箱_蝴蝶笼租赁_酷龙仓储笼租赁 测试治具|过炉治具|过锡炉治具|工装夹具|测试夹具|允睿自动化设备 | 万家财经_财经新闻_在线财经资讯网 | 直齿驱动-新型回转驱动和回转支承解决方案提供商-不二传动 | 泥浆在线密度计厂家-防爆数字压力表-膜盒-远传压力表厂家-江苏大亚自控设备有限公司 | 搪瓷搅拌器,搪玻璃搅拌器,搪玻璃冷凝器_厂家-淄博越宏化工设备 | 磁力抛光机_磁力研磨机_磁力去毛刺机-冠古设备厂家|维修|租赁【官网】 | 基本型顶空进样器-全自动热脱附解吸仪价格-AutoHS全模式-成都科林分析技术有限公司 | 锯边机,自动锯边机,双面涂胶机-建业顺达机械有限公司 | 换链神器官网-友情链接交换、购买交易于一体的站长平台 | 偏心半球阀-电动偏心半球阀-调流调压阀-旋球阀-上欧阀门有限公司 | 北京网络营销推广_百度SEO搜索引擎优化公司_网站排名优化_谷歌SEO - 北京卓立海创信息技术有限公司 | 小型玉石雕刻机_家用玉雕机_小型万能雕刻机_凡刻雕刻机官网 | 代写标书-专业代做标书-商业计划书代写「深圳卓越创兴公司」 | 菏泽商标注册_菏泽版权登记_商标申请代理_菏泽商标注册去哪里 | 带压开孔_带压堵漏_带压封堵-菏泽金升管道工程有限公司 | 真空搅拌机-行星搅拌机-双行星动力混合机-广州市番禺区源创化工设备厂 | 预制围墙_工程预制围墙_天津市瑞通建筑材料有限公司 | 东莞螺杆空压机_永磁变频空压机_节能空压机_空压机工厂批发_深圳螺杆空压机_广州螺杆空压机_东莞空压机_空压机批发_东莞空压机工厂批发_东莞市文颖设备科技有限公司 | 民用音响-拉杆音响-家用音响-ktv专用音响-万昌科技 | 工业车间焊接-整体|集中除尘设备-激光|等离子切割机配套除尘-粉尘烟尘净化治理厂家-山东美蓝环保科技有限公司 | 食药成分检测_调料配方还原_洗涤剂化学成分分析_饲料_百检信息科技有限公司 | 多米诺-多米诺世界纪录团队-多米诺世界-多米诺团队培训-多米诺公关活动-多米诺创意广告-多米诺大型表演-多米诺专业赛事 | 上海防爆真空干燥箱-上海防爆冷库-上海防爆冷柜?-上海浦下防爆设备厂家? | 耐火浇注料-喷涂料-浇注料生产厂家_郑州市元领耐火材料有限公司 耐力板-PC阳光板-PC板-PC耐力板 - 嘉兴赢创实业有限公司 | 创客匠人-让IP变现不走弯路| 噪声治理公司-噪音治理专业隔音降噪公司| 企业微信scrm管理系统_客户关系管理平台_私域流量运营工具_CRM、ERP、OA软件-腾辉网络 | 氧化锆纤维_1800度高温退火炉_1800度高温烧结炉-南京理工宇龙新材料股份有限公司 | 磁力抛光机_磁力研磨机_磁力去毛刺机-冠古设备厂家|维修|租赁【官网】 | 膜结构停车棚-自行车棚-膜结构汽车棚加工安装厂家幸福膜结构 | 防水套管_柔性防水套管_刚性防水套管-巩义市润达管道设备制造有限公司 |