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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python中goto的用法_python3里用goto

發(fā)布時(shí)間:2023/12/15 python 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python中goto的用法_python3里用goto 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

python里用goto也是小Pa最近做的項(xiàng)目里的一個(gè)需求。python不像C有自帶的goto, 需要用額外的包,目前為止,小pa只看到2個(gè)goto的包:

這2個(gè)小Pa都下載試用過,goto因?yàn)殚_發(fā)的時(shí)候比較早,對(duì)于python3的支持不太好,不推薦使用,目前推薦使用goto-statement, 這個(gè)project的熱度比較低,但是Forks/Stars的比率來說還是不錯(cuò)的。小Pa給它也貢獻(xiàn)1顆星,第761顆星星就是小Pa點(diǎn)的啦。goto-statement GitHub statistics

不過,用下來基本的功能還是可以的。

當(dāng)然,美中不足的是,goto-statement的最新的版本1.2還無法支持動(dòng)態(tài)的計(jì)算出的label.

goto-statement的貢獻(xiàn)作者Sebastian Noack本人也在和issue的提交者溝通時(shí),做了解釋:Thatgoto .foois technical parsed as attribute lookup is an implementation detail, and sincegetattr(goto, 'foo')results into different bytecode (it's a function call, not an attribute lookup on the bytecode-level), it is ignored when the@with_gotodecorator rewrites the bytecode. Furthermore, in order to support calculated jump targets, we'd have to keep a mapping of names and their destination, and resolve them at runtime. This is not supported at the moment, and might be impossible with the current approach, also considering that the bytecode to perform the jump (with the current approach) cannot be any larger than the original bytecode it replaces. However, one workaround would be, generating a string of Python code and usingexec(with_goto(compile(...)))after resolving all labels.

總之,目前想要在python3里實(shí)現(xiàn)goto, goto-statement是個(gè)不錯(cuò)的選擇,如果你有在實(shí)踐中發(fā)現(xiàn)更好的方法,歡迎交流!

總結(jié)

以上是生活随笔為你收集整理的python中goto的用法_python3里用goto的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。