Python internals: adding a new statement to Python
This article is an attempt tobetter understand how the front-end of Python works. Just reading documentationand source code may be a bit boring, so I’m taking a hands-on approach here:I’m going to add an until statement to Python.
All the coding for this article wasdone against the cutting-edge Py3k branch in the Python Mercurial repository mirror.
[size=15.0pt]The[size=15.0pt] [size=15.0pt]until[size=15.0pt] [size=15.0pt]statement[size=15.0pt]
[size=10.5pt]Some languages, like Ruby, have an until [size=10.5pt]statement, which is the complement to while [size=10.5pt](until num == 0 [size=10.5pt]is equivalent to while num != 0[size=10.5pt]). In Ruby, I can write:
CODE:
1.num = 32.until num == 0 do
3.puts num
4.num -= 1
5.end[size=10.5pt]And it will print:
CODE:
1.32.2
3.1[size=10.5pt]So, I want to add a similarcapability to Python. That is, being able to write:
CODE:
1.num = 32.until num == 0:
3.print(num)
4.num -= 1[size=10.5pt]
[size=10.5pt]
[size=10.5pt]
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-719756/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Generating a new SSH key and adding it to the SSH-agent
- Creating a Password File and Adding New Users to It (47)
- Python__new__和__init__Python
- python中__new__的使用注意Python
- Python中的__new__()詳解Python
- 【BO-SDK】-(RAS) Adding a new parameter_@old_devlib_04dev
- The Internals of PostgreSQLSQL
- oracle internalsOracle
- Python __new__ 和 __init__ 的區別Python
- Python 中__new__方法詳解及使用Python
- Oracle Index InternalsOracleIndex
- python中__init__ 和__new__的對比Python
- 詳解Python中的__init__和__new__Python
- The Internals of PostgreSQL學習SQL
- Oracle Database Internals FAQOracleDatabase
- ASM Metadata and InternalsASM
- 一問搞懂python的__init__和__new__方法Python
- python中的__init__ 、__new__、__call__小結Python
- Statement
- Python - 物件導向程式設計 - __new()__ 和單例模式Python物件程式設計單例模式
- Python面試之理解__new__和__init__的區別Python面試
- Python中__new__和__init__的區別與聯絡Python
- 簡述Python類中的 __init__、__new__、__call__ 方法Python
- Python中的__new__、__init__、__call__三個特殊方法Python
- Adding a Wordfile in Ultraedit
- Python語言中__init__與__new__的區別是什麼?Python
- Python類中__del__()、__call__()、__repr__()、__new__()、__hash__()方法Python
- go-internals 翻譯專案Go
- python2中的__new__與__init__,新式類和經典類Python
- JS - if else and else if statementJS
- GCC編譯遇到“a label can only be part of a statement and a declaration is not a statement”問題GC編譯
- [譯]深入理解JVM Understanding JVM InternalsJVM
- Oracle Internals Notes : Controlfile DumpsOracle
- JonathanLewis新書:Oracle Core: Essential Internals for DBAs and Developers新書OracleDeveloper
- Statement (操作 SQL 語句)SQL
- jdbc Statement和PrepareStatement操作JDBCREST
- New start new hope!
- Adding Drivers into VMWare ESXi Installation Image