麻豆黑色丝袜jk制服福利网站-麻豆精品传媒视频观看-麻豆精品传媒一二三区在线视频-麻豆精选传媒4区2021-在线视频99-在线视频a

千鋒教育-做有情懷、有良心、有品質(zhì)的職業(yè)教育機構(gòu)

手機站
千鋒教育

千鋒學(xué)習(xí)站 | 隨時隨地免費學(xué)

千鋒教育

掃一掃進入千鋒手機站

領(lǐng)取全套視頻
千鋒教育

關(guān)注千鋒學(xué)習(xí)站小程序
隨時隨地免費學(xué)習(xí)課程

當(dāng)前位置:首頁  >  技術(shù)干貨  > python閱讀代碼有助于養(yǎng)成優(yōu)秀的代碼風(fēng)格

python閱讀代碼有助于養(yǎng)成優(yōu)秀的代碼風(fēng)格

來源:千鋒教育
發(fā)布人:xqq
時間: 2023-11-07 19:12:23 1699355543

優(yōu)秀的代碼不需要文檔”,這句話雖然說的有些夸張的成份,但是也并無一定道理。優(yōu)秀的項目中的代碼,注釋占的比重是相當(dāng)大的。比方tornado框架中的代碼:

classHTTPServer(TCPServer,Configurable,

httputil.HTTPServerConnectionDelegate):

r"""Anon-blocking,single-threadedHTTPserver.

Aserverisdefinedbyasubclassof.HTTPServerConnectionDelegate,

or,forbackwardscompatibility,acallbackthattakesan

.HTTPServerRequestasanargument.Thedelegateisusuallya

tornado.web.Application.

HTTPServersupportskeep-aliveconnectionsbydefault

(automaticallyforHTTP/1.1,orforHTTP/1.0whentheclient

requestsConnection:keep-alive).

IfxheadersisTrue,wesupportthe

X-Real-Ip/X-Forwarded-Forand

X-Scheme/X-Forwarded-Protoheaders,whichoverridethe

remoteIPandURIscheme/protocolforallrequests.Theseheaders

areusefulwhenrunningTornadobehindareverseproxyorload

balancer.Theprotocolargumentcanalsobesettohttps

ifTornadoisrunbehindanSSL-decodingproxythatdoesnotsetoneof

thesupportedxheaders.

TomakethisserverserveSSLtraffic,sendthessl_optionskeyword

argumentwithanssl.SSLContextobject.Forcompatibilitywitholder

versionsofPythonssl_optionsmayalsobeadictionaryofkeyword

argumentsforthessl.wrap_socketmethod.::

ssl_ctx=ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)

ssl_ctx.load_cert_chain(os.path.join(data_dir,"mydomain.crt"),

os.path.join(data_dir,"mydomain.key"))

HTTPServer(applicaton,ssl_options=ssl_ctx)

HTTPServerinitializationfollowsoneofthreepatterns(the

initializationmethodsaredefinedontornado.tcpserver.TCPServer):

1.~tornado.tcpserver.TCPServer.listen:simplesingle-process::

server=HTTPServer(app)

server.listen(8888)

IOLoop.current().start()

Inmanycases,tornado.web.Application.listencanbeusedtoavoid

theneedtoexplicitlycreatetheHTTPServer.

2.~tornado.tcpserver.TCPServer.bind/~tornado.tcpserver.TCPServer.start:

simplemulti-process::

server=HTTPServer(app)

server.bind(8888)

server.start(0)#Forksmultiplesub-processes

IOLoop.current().start()

Whenusingthisinterface,an.IOLoopmust*not*bepassed

totheHTTPServerconstructor.~.TCPServer.startwillalwaysstart

theserveronthedefaultsingleton.IOLoop.

3.~tornado.tcpserver.TCPServer.add_sockets:advancedmulti-process::

sockets=tornado.netutil.bind_sockets(8888)

tornado.process.fork_processes(0)

server=HTTPServer(app)

server.add_sockets(sockets)

IOLoop.current().start()

The~.TCPServer.add_socketsinterfaceismorecomplicated,

butitcanbeusedwithtornado.process.fork_processesto

giveyoumoreflexibilityinwhentheforkhappens.

~.TCPServer.add_socketscanalsobeusedinsingle-process

serversifyouwanttocreateyourlisteningsocketsinsome

wayotherthantornado.netutil.bind_sockets.

..versionchanged::4.0

Addeddecompress_request,chunk_size,max_header_size,

idle_connection_timeout,body_timeout,max_body_size

arguments.Addedsupportfor.HTTPServerConnectionDelegate

instancesasrequest_callback.

..versionchanged::4.1

.HTTPServerConnectionDelegate.start_requestisnowcalledwith

twoarguments(server_conn,request_conn)(inaccordancewiththe

documentation)insteadofone(request_conn).

..versionchanged::4.2

HTTPServerisnowasubclassoftornado.util.Configurable.

"""

def__init__(self,*args,**kwargs):

#Ignoreargsto__init__;realinitializationbelongsin

#initializesincewe'reConfigurable.(there'ssomething

#weirdininitializationorderbetweenthisclass,

#Configurable,andTCPServersowecan'tleave__init__out

#completely)

pass

上面的注釋包含了:類的說明、例子、版本主要改動。

優(yōu)秀的代碼風(fēng)格:看到名字就能知道它是用來干什么的(顧名思義)、結(jié)構(gòu)清晰、代碼風(fēng)格統(tǒng)一(命名規(guī)則、格式)

這些優(yōu)秀的特質(zhì)都是為了:可讀性、容易理解。正如:代碼主要是給人看的,讓計算機運行是次要的

如果是在閱讀了不好的代碼,如果你心里在罵:“這代碼簡直是一坨

所以,自己的優(yōu)秀的編碼風(fēng)格也是成為一個合格的程序員必備的一項技能(面試要求會有這一項),通過閱讀代碼學(xué)習(xí),模仿優(yōu)秀的代碼風(fēng)格,有助于自己寫出‘漂亮’、整潔的代碼。

以上內(nèi)容為大家介紹了python閱讀代碼有助于養(yǎng)成優(yōu)秀的代碼風(fēng)格,希望對大家有所幫助,如果想要了解更多Python相關(guān)知識,請關(guān)注IT培訓(xùn)機構(gòu):千鋒教育。

聲明:本站稿件版權(quán)均屬千鋒教育所有,未經(jīng)許可不得擅自轉(zhuǎn)載。
10年以上業(yè)內(nèi)強師集結(jié),手把手帶你蛻變精英
請您保持通訊暢通,專屬學(xué)習(xí)老師24小時內(nèi)將與您1V1溝通
免費領(lǐng)取
今日已有369人領(lǐng)取成功
劉同學(xué) 138****2860 剛剛成功領(lǐng)取
王同學(xué) 131****2015 剛剛成功領(lǐng)取
張同學(xué) 133****4652 剛剛成功領(lǐng)取
李同學(xué) 135****8607 剛剛成功領(lǐng)取
楊同學(xué) 132****5667 剛剛成功領(lǐng)取
岳同學(xué) 134****6652 剛剛成功領(lǐng)取
梁同學(xué) 157****2950 剛剛成功領(lǐng)取
劉同學(xué) 189****1015 剛剛成功領(lǐng)取
張同學(xué) 155****4678 剛剛成功領(lǐng)取
鄒同學(xué) 139****2907 剛剛成功領(lǐng)取
董同學(xué) 138****2867 剛剛成功領(lǐng)取
周同學(xué) 136****3602 剛剛成功領(lǐng)取
相關(guān)推薦HOT
主站蜘蛛池模板: 日本高清二三四本2021第九页| 午夜无遮挡羞羞漫画免费| 久久99精品国产麻豆不卡| 美国式禁忌5太大了| 三级七日情| 中国一级黄色| 免费看美女脱衣服| 美女脱了内裤打开腿让你桶爽| 午夜爽爽| 国产乱视频| 中国陆超帅精瘦ktv直男少爷| 草草影院最新发布地址| 妞干网免费视频观看| 成品大香煮伊在2021一| 试看91福利区体验区120秒| 国产人妖系列在线精品| 美女张开腿让男人桶的视频| 快点使劲舒服爽视频| 十七岁高清在线观看| 本子库全彩无遮挡无翼乌触手| 国产三级精品三级| 日本欧美视频在线观看| 黑人异族日本人hd| 夫醉酒被公侵犯的电影中字版| 久久天天躁日日躁狠狠躁| 又色又爽又黄的视频网站| 老阿姨哔哩哔哩b站肉片茄子芒果| 精品国产综合区久久久久久| 美女被暴羞羞免费视频| www.插插插| 少妇激情av一区二区| 男人下面进女人下面视频免费| 美女扒开尿口让男生捅| 亚洲伦理一区二区| 国产精品亚洲片夜色在线| 好爽好深胸好大好多水视频| 国产特黄一级片| 久久66热这里只会有精品| 久久久久久福利| 处破女18分钟完整版| 午夜无遮挡羞羞漫画免费|