日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python中文件分类_Python中的类是否在不同的文件中?

發布時間:2025/4/16 python 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python中文件分类_Python中的类是否在不同的文件中? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在Python中,一個文件稱為

module.一個模塊可以由多個類或函數組成.

由于Python不僅僅是一種OO語言,所以沒有規則說明,一個文件只能包含一個類.

一個文件(模塊)應該包含屬于一起的類/功能,即提供類似的功能或相互依賴.

當然你不應該夸大這個.如果您的模塊由太多的類或功能組成,可讀性真的會受到影響.那么現在可能是將功能重新分組到不同的模塊中并創建packages.

對于命名約定,您可能需要閱讀PEP 8,但簡言之:

Class Names

Almost without exception, class names use the CapWords convention.

Classes for internal use have a leading underscore in addition.

Package and Module Names

Modules should have short, all-lowercase names. Underscores can be used

in the module name if it improves readability. Python packages should

also have short, all-lowercase names, although the use of underscores is

discouraged.

Since module names are mapped to file names, and some file systems are

case insensitive and truncate long names, it is important that module

names be chosen to be fairly short — this won’t be a problem on Unix,

but it may be a problem when the code is transported to older Mac or

Windows versions, or DOS.

要實例化對象,您必須在文件中導入類.例如

>>> from mymodule import MyClass

>>> obj = MyClass()

要么

>>> import mymodule

>>> obj = mymodule.MyClass()

要么

>>> from mypackage.mymodule import MyClass

>>> obj = MyClass()

你正在詢問基本的基本東西,所以我建議閱讀tutorial.

總結

以上是生活随笔為你收集整理的python中文件分类_Python中的类是否在不同的文件中?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。