久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

    <small id='DHSIM'></small><noframes id='DHSIM'>

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

      <bdo id='DHSIM'></bdo><ul id='DHSIM'></ul>

      python函數可以調用同名的全局函數嗎?

      can a python function call a global function with the same name?(python函數可以調用同名的全局函數嗎?)

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

          <legend id='lasE4'><style id='lasE4'><dir id='lasE4'><q id='lasE4'></q></dir></style></legend>
            <tbody id='lasE4'></tbody>

          <tfoot id='lasE4'></tfoot>
          • <small id='lasE4'></small><noframes id='lasE4'>

              <bdo id='lasE4'></bdo><ul id='lasE4'></ul>
              1. 本文介紹了python函數可以調用同名的全局函數嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我可以從同名函數調用全局函數嗎?

                Can I call a global function from a function that has the same name?

                例如:

                def sorted(services):
                    return {sorted}(services, key=lambda s: s.sortkey())
                

                {sorted} 我的意思是全局排序函數.有沒有辦法做到這一點?然后我想用模塊名稱調用我的函數:service.sorted(services)

                By {sorted} I mean the global sorted function. Is there a way to do this? I then want to call my function with the module name: service.sorted(services)

                我想使用相同的名稱,因為它與全局函數做同樣的事情,只是它添加了一個默認參數.

                I want to use the same name, because it does the same thing as the global function, except that it adds a default argument.

                推薦答案

                Python 的名稱解析方案有時被稱為 LEGB 規則,這意味著當您在函數中使用非限定名稱時,Python 最多搜索四個范圍——首先本地 (L) 范圍,然后是任何封閉 (E) deflambda 的本地范圍s,然后是全局 (G) 范圍,最后是內置 (B) 范圍.(請注意,一旦找到匹配項,它將立即停止搜索)

                Python's name-resolution scheme which sometimes is referred to as LEGB rule, implies that when you use an unqualified name inside a function, Python searches up to four scopes— First the local (L) scope, then the local scopes of any enclosing (E) defs and lambdas, then the global (G) scope, and finally the built-in (B) scope. (Note that it will stops the search as soon as it finds a match)

                因此,當您在函數解釋器中使用 sorted 時,會將其視為 全局 名稱(您的函數名稱),因此您將擁有一個遞歸函數.如果你想訪問內置的 sorted 你需要為 Python 指定它.通過 __builtin__ 模塊(在 Python-2.x 中)和 builtins 在 Python-3.x 中(此模塊提供對 Python 的所有內置"標識符的直接訪問)

                So when you use sorted inside the functions interpreter considers it as a Global name (your function name) so you will have a recursion function. if you want to access to built-in sorted you need to specify that for Python . by __builtin__ module (in Python-2.x ) and builtins in Python-3.x (This module provides direct access to all ‘built-in’ identifiers of Python)

                蟒蛇2:

                import __builtin__
                def sorted(services):
                    return __builtin__.sorted(services, key=lambda s: s.sortkey())
                

                蟒蛇3:

                import builtins
                def sorted(services):
                    return builtins.sorted(services, key=lambda s: s.sortkey())
                

                這篇關于python函數可以調用同名的全局函數嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 包)
                <tfoot id='FCKir'></tfoot>

                1. <small id='FCKir'></small><noframes id='FCKir'>

                  <i id='FCKir'><tr id='FCKir'><dt id='FCKir'><q id='FCKir'><span id='FCKir'><b id='FCKir'><form id='FCKir'><ins id='FCKir'></ins><ul id='FCKir'></ul><sub id='FCKir'></sub></form><legend id='FCKir'></legend><bdo id='FCKir'><pre id='FCKir'><center id='FCKir'></center></pre></bdo></b><th id='FCKir'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='FCKir'><tfoot id='FCKir'></tfoot><dl id='FCKir'><fieldset id='FCKir'></fieldset></dl></div>
                      <legend id='FCKir'><style id='FCKir'><dir id='FCKir'><q id='FCKir'></q></dir></style></legend>
                      • <bdo id='FCKir'></bdo><ul id='FCKir'></ul>
                          <tbody id='FCKir'></tbody>
                          主站蜘蛛池模板: www.狠狠操.com| 黄色网av| 日韩欧美在线观看 | 欧美亚洲在线 | 日韩中文字幕免费 | 国产黄色一区 | 青青久久久 | 久久这里只有精品6 | 久久一区视频 | 日韩免费在线观看 | 欧美成人综合 | 久久久久久久国产精品 | 黄色三级免费 | 伊人天堂网 | 日韩成人在线观看 | 全部免费毛片在线播放高潮 | 日韩精品免费观看 | 亚洲欧美视频在线 | 亚洲欧美日韩另类 | 日韩一区二区中文字幕 | 日本韩国三级 | 欧美丰满少妇 | 日本美女性生活 | 国产精品欧美精品 | 亚洲精品一二三区 | 国产特级黄色片 | 欧美久久久久久 | 久久久久久免费毛片精品 | 国产精品一级 | 中文字幕在线一区二区三区 | 欧美日韩a| 日韩成人在线播放 | av在线免费观看网站 | 日本免费一级片 | 国产成人精品一区二区三区在线 | 亚洲观看黄色网 | 国产一区二区三区在线观看视频 | 亚洲一区二区免费 | 国产伦精品一区二区三区四区 | 天堂资源 | 银杏av|