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

    <legend id='hZkK3'><style id='hZkK3'><dir id='hZkK3'><q id='hZkK3'></q></dir></style></legend>
    • <bdo id='hZkK3'></bdo><ul id='hZkK3'></ul>

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

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

    <tfoot id='hZkK3'></tfoot>

        在 Python 中使用類作為命名空間是個好主意嗎

        Is it a good idea to using class as a namespace in Python(在 Python 中使用類作為命名空間是個好主意嗎)
        <i id='7ZTUB'><tr id='7ZTUB'><dt id='7ZTUB'><q id='7ZTUB'><span id='7ZTUB'><b id='7ZTUB'><form id='7ZTUB'><ins id='7ZTUB'></ins><ul id='7ZTUB'></ul><sub id='7ZTUB'></sub></form><legend id='7ZTUB'></legend><bdo id='7ZTUB'><pre id='7ZTUB'><center id='7ZTUB'></center></pre></bdo></b><th id='7ZTUB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='7ZTUB'><tfoot id='7ZTUB'></tfoot><dl id='7ZTUB'><fieldset id='7ZTUB'></fieldset></dl></div>

          <tbody id='7ZTUB'></tbody>
        • <small id='7ZTUB'></small><noframes id='7ZTUB'>

        • <legend id='7ZTUB'><style id='7ZTUB'><dir id='7ZTUB'><q id='7ZTUB'></q></dir></style></legend>

              • <bdo id='7ZTUB'></bdo><ul id='7ZTUB'></ul>

                  <tfoot id='7ZTUB'></tfoot>
                1. 本文介紹了在 Python 中使用類作為命名空間是個好主意嗎的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我將一堆相關的東西放到一個類中.主要目的是將它們組織成一個命名空間.

                  I am putting a bunch of related stuff into a class. The main purpose is to organize them into a namespace.

                  class Direction:
                  
                    north = 0
                    east = 1
                    south = 2
                    west = 3
                  
                    @staticmethod
                    def turn_right(d):
                      return turn_to_the_right
                  
                    @staticmethod
                    def turn_left(d):
                      return turn_to_the_left
                  
                  
                  
                  # defined a short alias because direction will be used a lot
                  D = Direction
                  
                  d0 = D.north
                  d1 = D.turn_right(d)
                  

                  涉及的對象概念并不多.在 C++ 中,我將使用實際的語言關鍵字 namespace.Python中沒有這樣的東西.所以我試圖使用 class 來達到這個目的.

                  There is not much object concept involved. In C++, I will be using the actual language keyword namespace. There is no such thing in Python. So I am trying to use class for this purpose.

                  這是個好主意嗎?這種方法有什么陷阱嗎?

                  Is this a good idea? Any pitfall with this approach?

                  我昨天剛剛回答了一個相關問題.這個問題以不同的方式提出.這是我需要為自己做出的實際決定.

                  I've just answer a related question yesterday. This question is asked in a different way. It is an actual decision I need to make for myself.

                  python中的靜態方法與模塊函數 - 代碼日志

                  Static method vs module function in python - Stack Overflow

                  python中的靜態方法與模塊函數

                  推薦答案

                  是的,確實.您可以將 Python 類嚴格用于命名空間,因為這是它們可以做的特殊事情之一,并且與模塊不同.在文件中將類定義為內聯命名空間比生成更多文件要容易得多.你不應該在沒有評論你的代碼說明它的用途的情況下這樣做.Python 類有很多不同的形式和用途,這讓您難以理解以前從未見過的代碼.

                  Yes, indeed. You can use Python classes strictly for namespacing as that is one of the special things they can do and do differently than modules. It's a lot easier to define a class as a namespace inline in a file than to generate more files. You should not do it without commenting your code saying what it's for. Python classes come in a lot of different forms and purposes and this makes difficulty understanding code you have not seen before.

                  用作命名空間的 Python 類不亞于 Python 類,它滿足對其他語言中類的理解.Python 不需要實例化一個類就可以使用.它不需要 ivars 也不需要方法.它相當靈活.

                  A Python class used as a namespace is no less a Python class than one that meets the perception of what a class is in other languages. Python does not require a class to be instantiated to be useful. It does not require ivars and does not require methods. It is fairly flexible.

                  類也可以包含其他類.

                  很多人對什么是 Pythonic 或不是 Pythonic 都有自己的想法.但是如果他們都擔心一致性之類的東西,他們會推動擁有像 len() dir()help() 這樣的東西是對象的方法而不是全局函數.

                  Lots of people have their ideas about what is or isn't Pythonic. But if they were all worried about something like consistency, they'd push to have things like len() dir() and help() be a method of objects rather than a global function.

                  做有效的事,如果不常用或不明顯的用法,請對其進行評論/記錄.

                  Do what works, comment / document it if it isn't usual or obvious usage.

                  這篇關于在 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 包)
                    <tbody id='4jeDY'></tbody>
                  <legend id='4jeDY'><style id='4jeDY'><dir id='4jeDY'><q id='4jeDY'></q></dir></style></legend>
                  <i id='4jeDY'><tr id='4jeDY'><dt id='4jeDY'><q id='4jeDY'><span id='4jeDY'><b id='4jeDY'><form id='4jeDY'><ins id='4jeDY'></ins><ul id='4jeDY'></ul><sub id='4jeDY'></sub></form><legend id='4jeDY'></legend><bdo id='4jeDY'><pre id='4jeDY'><center id='4jeDY'></center></pre></bdo></b><th id='4jeDY'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4jeDY'><tfoot id='4jeDY'></tfoot><dl id='4jeDY'><fieldset id='4jeDY'></fieldset></dl></div>
                    <bdo id='4jeDY'></bdo><ul id='4jeDY'></ul>

                    <tfoot id='4jeDY'></tfoot>

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

                            主站蜘蛛池模板: 成年人免费看视频 | 免费99精品国产自在在线 | 国产综合区 | 亚洲免费一区二区 | 在线观看日韩av | 亚洲福利在线观看 | 超碰在线观看97 | 91亚洲国产 | 免费观看全黄做爰的视频 | 一区二区三区四区精品 | 国产成人午夜高潮毛片 | 久久99国产精品 | 欧美精品亚洲 | 亚洲区一区二 | 欧美精品久久久久 | 国产农村妇女精品一二区 | 伊人网视频 | 国产理论在线观看 | 成人三级在线观看 | 国产中文在线观看 | 小镇姑娘国语版在线观看免费 | 久操视频在线观看 | 这里只有精品视频在线观看 | 91久久久久久久 | 中文字幕日韩高清 | 丁香九月婷婷 | 久久精品国产77777蜜臀 | 欧美在线天堂 | 久久久九九 | 狠狠做深爱婷婷综合一区 | 人人超碰人人 | 亚洲第一伊人 | 久久精品视频99 | 日韩欧美高清 | 日韩欧美国产高清91 | 91午夜精品 | 国产精品96 | 国产www在线观看 | 婷婷在线播放 | 精品国产毛片 | 久久久久久毛片 |