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

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

      <tfoot id='i3PtZ'></tfoot>

      <i id='i3PtZ'><tr id='i3PtZ'><dt id='i3PtZ'><q id='i3PtZ'><span id='i3PtZ'><b id='i3PtZ'><form id='i3PtZ'><ins id='i3PtZ'></ins><ul id='i3PtZ'></ul><sub id='i3PtZ'></sub></form><legend id='i3PtZ'></legend><bdo id='i3PtZ'><pre id='i3PtZ'><center id='i3PtZ'></center></pre></bdo></b><th id='i3PtZ'></th></span></q></dt></tr></i><div class="3zxwvbv" id='i3PtZ'><tfoot id='i3PtZ'></tfoot><dl id='i3PtZ'><fieldset id='i3PtZ'></fieldset></dl></div>
    1. <small id='i3PtZ'></small><noframes id='i3PtZ'>

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

      1. exec() 方法中自定義命名空間的子類化 python 字典

        subclassed python dictionary for custom namespace in exec() method(exec() 方法中自定義命名空間的子類化 python 字典)
            <bdo id='VoVGr'></bdo><ul id='VoVGr'></ul>
            <tfoot id='VoVGr'></tfoot>
            • <small id='VoVGr'></small><noframes id='VoVGr'>

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

              1. <legend id='VoVGr'><style id='VoVGr'><dir id='VoVGr'><q id='VoVGr'></q></dir></style></legend>

                  本文介紹了exec() 方法中自定義命名空間的子類化 python 字典的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試對字典進行子類化以在 exec 方法中使用.最終,我希望本地函數(shù)具有自定義名稱范圍行為.

                  I am trying to subclass a dictionary for use in an exec method. Ultimately, I would like the local function to have a custom name scoping behaviour.

                  在下面的代碼中,函數(shù) b() 實際上確實有正確的 globals() 字典可供它使用,但是在解析 z.

                  In the code below, function b() does in fact have the correct globals() dictionary available to it, however it fails to search it when resolving z.

                  函數(shù)b()是否先不搜索locals()然后globals()?

                  Does function b() first not search locals() then globals() ?

                  非常令人費解.任何幫助表示贊賞.

                  Very puzzling. Any help appreciated.

                  t = '''
                  def b():
                  #   return (globals()['z']) #works
                      return z #fails
                  
                  b()
                  '''
                  
                  class MyDict(dict):
                      def __init__(self, g):
                          dict.__init__(self)
                          self.my_g = g
                  
                  
                      def __getitem__(self, key):
                          print("GET ", key)
                          try:
                              val = dict.__getitem__(self, key)
                          except:
                              print("GET exception1")
                              val = self.my_g[key]
                          return val
                  
                  
                  g = {'z':123}
                  
                  md = MyDict(g)
                  
                  #fails to find z
                  exec(t, md, md)
                  
                  #works
                  #exec(t, g, g)
                  

                  輸出

                  GET  b
                  Traceback (most recent call last):
                    File "/project1/text12", line 31, in <module>
                    File "<string>", line 6, in <module>
                    File "<string>", line 4, in b
                  NameError: global name 'z' is not defined
                  

                  推薦答案

                  在 python 3.3 之前,您不能globals 使用自定義 dict 子類 exec 語句的值.執(zhí)行編譯代碼的底層 C 代碼直接訪問底層 C 結構,忽略您可能已經(jīng)實現(xiàn)的任何自定義掛鉤.

                  Before python 3.3, you cannot use a custom dict subclass for the globals value of an exec statement. The underlying C code that executes the compiled code accesses the underlying C structures directly, ignoring any custom hooks you may have implemented.

                  換句話說,當代碼執(zhí)行 LOAD_GLOBAL 操作時(就像函數(shù) b 中的 z 一樣),C字節(jié)碼評估循環(huán)使用 globals 結構">C API,繞過任何 python 覆蓋.

                  In other words, when the code does a LOAD_GLOBAL operation (as is the case with z in your function b), the C bytecode evaluation loop accesses the globals structure in the current frame using the C API, bypassing any python overrides.

                  這記錄在 exec()功能文檔 as:

                  This is documented in the exec() function documentation as:

                  如果只提供了globals,它必須是一個字典,它將用于全局和局部變量.如果給出了 globalslocals,則它們分別用于全局變量和局部變量.如果提供,locals 可以是任何映射對象.

                  If only globals is provided, it must be a dictionary, which will be used for both the global and the local variables. If globals and locals are given, they are used for the global and local variables, respectively. If provided, locals can be any mapping object.

                  此限制已在 Python 3.3 中放寬,請參閱 issue 14385.文檔尚未更新,但字節(jié)碼評估循環(huán)已更新,以在回退到 C API 訪問之前測試自定義映射.如果使用自定義映射,則使用 PyObject_GetItem 函數(shù),該函數(shù)將在自定義類上調(diào)用 __getitem__.

                  This restriction has been loosened in Python 3.3, see issue 14385. The documentation hasn't been updated yet, but the bytecode evaluation loop has been updated to test for custom mappings before falling back to the C API access. If a custom mapping is used, the PyObject_GetItem function is used, which will call __getitem__ on custom classes.

                  這篇關于exec() 方法中自定義命名空間的子類化 python 字典的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關文檔推薦

                  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(分發(fā)帶有已編譯動態(tài)共享庫的 Python 包)
                    <tbody id='BWFcX'></tbody>
                      <bdo id='BWFcX'></bdo><ul id='BWFcX'></ul>

                        • <i id='BWFcX'><tr id='BWFcX'><dt id='BWFcX'><q id='BWFcX'><span id='BWFcX'><b id='BWFcX'><form id='BWFcX'><ins id='BWFcX'></ins><ul id='BWFcX'></ul><sub id='BWFcX'></sub></form><legend id='BWFcX'></legend><bdo id='BWFcX'><pre id='BWFcX'><center id='BWFcX'></center></pre></bdo></b><th id='BWFcX'></th></span></q></dt></tr></i><div class="8uikfi2" id='BWFcX'><tfoot id='BWFcX'></tfoot><dl id='BWFcX'><fieldset id='BWFcX'></fieldset></dl></div>
                          <tfoot id='BWFcX'></tfoot>

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

                        • <small id='BWFcX'></small><noframes id='BWFcX'>

                          1. 主站蜘蛛池模板: 不锈钢发酵罐_水果酒发酵罐_谷物发酵罐_山东誉诚不锈钢制品有限公司 | 济南网站建设|济南建网站|济南网站建设公司【济南腾飞网络】【荐】 | 单电机制砂机,BHS制砂机,制沙机设备,制砂机价格-正升制砂机厂家 单级/双级旋片式真空泵厂家,2xz旋片真空泵-浙江台州求精真空泵有限公司 | 刺绳_刀片刺网_刺丝滚笼_不锈钢刺绳生产厂家_安平县浩荣金属丝网制品有限公司-安平县浩荣金属丝网制品有限公司 | STRO|DTRO-STRO反渗透膜(科普)_碟滤 | 悬浮拼装地板_篮球场木地板翻新_运动木地板价格-上海越禾运动地板厂家 | 阻垢剂-反渗透缓蚀阻垢剂厂家-山东鲁东环保科技有限公司 | 上海佳武自动化科技有限公司 | 砂磨机_立式纳米砂磨机_实验室砂磨机-广州儒佳化工设备厂家 | 车间除尘设备,VOCs废气处理,工业涂装流水线,伸缩式喷漆房,自动喷砂房,沸石转轮浓缩吸附,机器人喷粉线-山东创杰智慧 | 信阳网站建设专家-信阳时代网联-【信阳网站建设百度推广优质服务提供商】信阳网站建设|信阳网络公司|信阳网络营销推广 | 低噪声电流前置放大器-SR570电流前置放大器-深圳市嘉士达精密仪器有限公司 | 制丸机,小型中药制丸机,全自动制丸机价格-甘肃恒跃制药设备有限公司 | 自清洗过滤器_全自动过滤器_全自动反冲洗过滤器_量子过滤器-滑漮滴 | TTCMS自助建站_网站建设_自助建站_免费网站_免费建站_天天向上旗下品牌 | 实体店商新零售|微赢|波后|波后合作|微赢集团| 小型铜米机-干式铜米机-杂线全自动铜米机-河南鑫世昌机械制造有限公司 | 天津市能谱科技有限公司-专业的红外光谱仪_红外测油仪_紫外测油仪_红外制样附件_傅里叶红外光谱技术生产服务厂商 | 超细|超微气流粉碎机|气流磨|气流分级机|粉体改性机|磨粉机|粉碎设备-山东埃尔派粉体科技 | [官网]叛逆孩子管教_戒网瘾学校_全封闭问题青少年素质教育_新起点青少年特训学校 | 南京泽朗生物科技有限公司-液体饮料代加工_果汁饮料代加工_固体饮料代加工 | 杭州可当科技有限公司—流量卡_随身WiFi_AI摄像头一站式解决方案 | Boden齿轮油泵-ketai齿轮泵-yuken油研-无锡新立液压有限公司 | 地磅-地秤-江阴/无锡地磅-江阴天亿计量设备有限公司_ | 三轴曲线机-端子插拔力试验机|华杰仪器 | 澳威全屋定制官网|极简衣柜十大品牌|衣柜加盟代理|全屋定制招商 百度爱采购运营研究社社群-店铺托管-爱采购代运营-良言多米网络公司 | 泡沫消防车_水罐消防车_湖北江南专用特种汽车有限公司 | 闪蒸干燥机-喷雾干燥机-带式干燥机-桨叶干燥机-[常州佳一干燥设备] | 书法培训-高考书法艺考培训班-山东艺霖书法培训凭实力挺进央美 | 嘉兴泰东园林景观工程有限公司_花箱护栏| 书法培训-高考书法艺考培训班-山东艺霖书法培训凭实力挺进央美 | 环境模拟实验室_液体-气体控温机_气体控温箱_无锡双润冷却科技有限公司 | 高柔性拖链电缆-聚氨酯卷筒电缆-柔性屏蔽电缆厂家-玖泰电缆 | 厂厂乐-汇聚海量采购信息的B2B微营销平台-厂厂乐官网 | 山东石英砂过滤器,除氟过滤器「价格低」-淄博胜达水处理 | 登车桥动力单元-非标液压泵站-非标液压系统-深圳市三好科技有限公司 | 慢回弹测试仪-落球回弹测试仪-北京冠测精电仪器设备有限公司 | 退火炉,燃气退火炉,燃气热处理炉生产厂家-丹阳市丰泰工业炉有限公司 | 细砂提取机,隔膜板框泥浆污泥压滤机,螺旋洗砂机设备,轮式洗砂机械,机制砂,圆锥颚式反击式破碎机,振动筛,滚筒筛,喂料机- 上海重睿环保设备有限公司 | 江西自考网 | 杭州翻译公司_驾照翻译_专业人工翻译-杭州以琳翻译有限公司官网 组织研磨机-高通量组织研磨仪-实验室多样品组织研磨机-东方天净 |