Rock It 《ML》JupyterLab 【丁】Code《七》語義【四】III‧終

就讓我們從《人工智慧!!》一文中所講的『哲學爭論』︰

一九八零年希爾勒寫了一篇論文《心靈、大腦、與程式》Minds, Brains, and Programs,講到一個稱作『中文房間』Chinese room 的思想實驗︰

220px-Salachinesa2

一 位中文一竅不通,以英文為母語的人,關閉在一間只有一個開口的密閉房間中。房間裡有一本英文手冊以及伴隨著的電腦程式,還有充足的紙、筆、橡皮擦與檔案 櫃。門外的人從那個開口向房間內輸入中文之字詞,門裡的人便按照程式指令處理,再由那個開口輸出中文字詞。假使該程式已然通過中文的圖零測試,當然那人自 可以作剛才所說的這件事情。他只需簡單『用手』manually 來跑程式就好了。

希爾勒認為,儘管門裡的人很能夠以假亂真,讓門外的人以為他本就是華語使用者,然而他卻是壓根不懂中文的啊!假使門裡的人是『不可能』透過英文手冊來『理解』中文的話,那麼電腦也是不可能借著程式來獲得這個『理解力』的吧!!

有 批評者這麼說︰人們都認為人是擁有智慧的,然而人的智慧卻是來自於腦細胞的物理訊息轉換作用,單一個腦細胞並不能理解字詞的意義,難道不是大量的腦細胞造 就了人 類的認知與理解能力的嗎?這跟有眾多指令組成的整體程式又能有什麼實質的差異呢?所以為什麼電腦就不可能會有『理解力』的呢??

,展開『新世界』科技的探索。

─── 《勇闖新世界︰《邏輯編程》

 

凡人都有『左』、『右』二腦,故人工智慧深度神經網路學習終將追求融會有『全腦』吧◎

因此才舉

26.7. 2to3 – Automated Python 2 to 3 code translation

2to3 is a Python program that reads Python 2.x source code and applies a series of fixers to transform it into valid Python 3.x code. The standard library contains a rich set of fixers that will handle almost all code. 2to3 supporting library lib2to3 is, however, a flexible and generic library, so it is possible to write your own fixers for 2to3. lib2to3could also be adapted to custom applications in which Python code needs to be edited automatically.

26.7.1. Using 2to3

2to3 will usually be installed with the Python interpreter as a script. It is also located in the Tools/scripts directory of the Python root.

2to3’s basic arguments are a list of files or directories to transform. The directories are recursively traversed for Python sources.

Here is a sample Python 2.x source file, example.py:

def greet(name):
    print "Hello, {0}!".format(name)
print "What's your name?"
name = raw_input()
greet(name)

It can be converted to Python 3.x code via 2to3 on the command line:

2to3 example.py</pre> <span style="color: #008080;">A diff against the original source file is printed. 2to3 can also write the needed modifications right back to the source file. (A backup of the original file is made unless <code class="xref std std-option docutils literal notranslate"><span class="pre">-n</span></code> is also given.) Writing the changes back is enabled with the <code class="xref std std-option docutils literal notranslate"><span class="pre">-w </span></code>flag:</span> <pre class="lang:default decode:true "> 2to3 -w example.py

After transformation, example.py looks like this:

def greet(name):
    print("Hello, {0}!".format(name))
print("What's your name?")
name = input()
greet(name)

Comments and exact indentation are preserved throughout the translation process.

 

的範例,呈現『紅男爵』之威力強大也︰

 

閱歷者,深知啟始時步履維艱呦

/cpython

cpython/Lib/lib2to3/

……

眼下只需喝杯咖啡,讀讀

This is the reference page for every node type encountered in RedBaron and their specificities.

TopClass

CodeBlockNode

CodeBlockNode is a type of node that has a body composed of indented code like the DefNode or the IfNode. Great care has been taken on the SetAttr of their value so you don’t have to take care about reindenting and other formatting details.

Demonstration:

In [1]: red = RedBaron("def function():\n    pass\n")

In [2]: red
Out[2]: 
0   def function():
        pass
    

In [3]: red[0].value = "stuff"  # first '\n' will be added, indentation will be set

In [4]: red
Out[4]: 
0   def function():
        stuff
    

In [5]: red[0].value = "                    bad_indent"

In [6]: red
Out[6]: 
0   def function():
        bad_indent
    

In [7]: red[0].value = " some\n stuff"

In [8]: red
Out[8]: 
0   def function():
        some
        stuff

………

想想難易其來,自可得矣☆