久久久久久久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函數(shù)可以調(diào)用同名的全局函數(shù)嗎?

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

        <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函數(shù)可以調(diào)用同名的全局函數(shù)嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習吧!

                問題描述

                我可以從同名函數(shù)調(diào)用全局函數(shù)嗎?

                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} 我的意思是全局排序函數(shù).有沒有辦法做到這一點?然后我想用模塊名稱調(diào)用我的函數(shù):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)

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

                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 規(guī)則,這意味著當您在函數(shù)中使用非限定名稱時,Python 最多搜索四個范圍——首先本地 (L) 范圍,然后是任何封閉 (E) deflambda 的本地范圍s,然后是全局 (G) 范圍,最后是內(nèi)置 (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)

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

                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())
                

                這篇關(guān)于python函數(shù)可以調(diào)用同名的全局函數(shù)嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guā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(如何在不重復(fù)導(dǎo)入頂級名稱的情況下構(gòu)造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 包)
                <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>
                          主站蜘蛛池模板: 久久99国产精一区二区三区 | 一二三四在线视频观看社区 | 亚洲3级| 欧美国产日韩在线 | 国产精品久久久久久久久久久久久久 | 久久99视频免费观看 | 亚洲成人免费视频在线观看 | 亚洲精品乱码久久久久久蜜桃91 | 国产精品99久久久久久久vr | 亚洲高清网 | 欧美精品久久久久久久久老牛影院 | 不卡一区 | 国产91在线播放精品91 | av在线天天| 国产色片 | 精品欧美一区二区三区久久久 | 国产美女特级嫩嫩嫩bbb片 | 日韩av一区二区在线观看 | 日韩av资源站| 国产视频三级 | 亚洲国产区 | 久久精品国产一区二区三区不卡 | 欧美精品乱码久久久久久按摩 | 国产午夜精品理论片a大结局 | 久久婷婷av | 怡红院成人在线视频 | 亚洲精品一区二区在线观看 | 福利片在线看 | 久久久999成人 | 国产精品高潮呻吟久久 | 久久久久久久一区 | 国产成人免费视频网站高清观看视频 | 日韩在线欧美 | 国产一区二区三区在线观看免费 | 国产精品1区 | 亚洲国产中文在线 | 日韩久久久久久 | 看a网站 | 一区二区片 | 久久综合一区二区三区 | 日韩在线精品视频 |