久久久久久久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中的靜態(tài)方法與模塊函數(shù) - 代碼日志

                  Static method vs module function in python - Stack Overflow

                  python中的靜態(tài)方法與模塊函數(shù)

                  推薦答案

                  是的,確實.您可以將 Python 類嚴格用于命名空間,因為這是它們可以做的特殊事情之一,并且與模塊不同.在文件中將類定義為內(nèi)聯(lián)命名空間比生成更多文件要容易得多.你不應該在沒有評論你的代碼說明它的用途的情況下這樣做.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() 這樣的東西是對象的方法而不是全局函數(shù).

                  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模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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(如何在不重復導入頂級名稱的情況下構(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 包)
                    <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'>

                            主站蜘蛛池模板: 久久这里只有精品首页 | 天堂亚洲 | 久久国产欧美日韩精品 | 狠狠色综合网站久久久久久久 | 亚洲精品亚洲人成人网 | 一区二区三区av | 国产精品成人国产乱一区 | 国产精品成人一区二区三区夜夜夜 | 福利精品 | 日韩在线h | 日韩精品一区在线观看 | 久久精品国产99国产精品 | 在线一区视频 | 中文在线亚洲 | 国产精品永久免费 | 欧美激情国产日韩精品一区18 | 在线国产一区二区 | 亚洲福利在线视频 | 欧美日韩精品久久久免费观看 | 精品一区二区三区四区五区 | 日韩av成人| 一区二区三区视频在线免费观看 | av片免费观看 | 伊人色综合久久天天五月婷 | 亚洲国产精品日本 | 国产日韩一区二区三区 | 午夜寂寞影院在线观看 | 日韩精品成人在线 | 久久亚洲天堂 | 欧美久久一级 | 日韩精品久久久久 | 欧美精品二区 | 久久久精品日本 | 成年人在线观看 | 妞干网视频| 久久久久久久久久久高潮一区二区 | 嫩呦国产一区二区三区av | 亚洲成人免费在线观看 | 青青草一区二区 | a免费观看| 一区二区三区久久久 |