SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Downloaden Sie, um offline zu lesen
1
PyCon JP 2015
Renyuan Lyu
呂仁園
Yunghsin Kuo
郭詠欣
Translation of Python Programs
into non-English Languages
for Learners without English Proficiency
Oct/11/日曜日 3:35 p.m.–4:05 p.m. in メディアホール/Media Hall
Chang Gung Univ.
Taiwan
Visit my Blog for more Info
http://apython.blogspot.tw/
2
Computer
Programming
for everybody!
No matter Old or Young
No matter Boys or Girls
Picture from Pycon JP 2015
https://www.python.org/doc/essays/cp4e/
By Guido van Rossum
3
Computer Programming
for everybody?
As long as she/he knows the
English language!
4
Is it possible
that the English language
is the first barrier for people
to learn programming?
In what language,
you teach your kids
the fundamental math or science?
Python Turtle Graphics
in Traditional Chinese (Kanji)
傳統漢字の Python 龜作圖
5
Also appeared on Pycon APAC 2015
without technical detail
http://apython.blogspot.tw
This slide is here
2 Main Points
• Python Programming in non-English
Language improves readability for
non-native English speakers
• A set of 18 Turtle Demo Programs
were Translated into Traditional
Chinese as an Example
6
The term “Traditional Chinese” in this presentation may sometimes
be used interchangeably with “Kanji”.
Abstract
• A set of 18 turtle demo programs has been
translated into traditional Chinese (tc)
• as an example to show the possibility to write Python code
conveniently in non-English language.
• To improve code clarity and readability
• for non-native English speakers, according to Python PEP
3131.
• To attract more people to learn programming
• who are considered as less English proficiency.
• Providing a full list of tc alias (turtle_tc.py)
• for the official python turtle module.
• Github Availability
7http://github.com/renyuanL/pythonTurtleInChinese
8
https://youtu.be/MXAL3VkxeEk
https://www.dropbox.com/s/451wqq7
vblll63j/PyConApac2015_Booth11_en_
tc_jp.mp4?dl=0
A quick Glance of Demonstration
The motivation was partially from
PEP 3131: "Supporting Non-ASCII Identifiers"
• many people in the world not familiar with the
English language
– They’d like to define variables, functions and classes
with names in their native languages
• code clarity and maintainability of the code
among speakers of that language improves.
• Original from PEP 3131 :
[https://www.python.org/dev/peps/pep-3131/]
9
One Glance at Python Code
in English v.s. in Kanji
from turtle import *
print("Hello, this is turtle graphics.")
for i in range(100):
forward(100)
left(100)
from turtle_tc import *
印("哈囉,這是龜作圖。")
for i in 範圍(100):
前進(100)
左轉(100)
10
The first impression
of this kind of program:
SHORTER in length,
more compact,
and more readable,
if you understand kanji (漢字).
Ignition:
UTF-8 as Source encoding
• After version 3.0, the Python language has changed its
source coding from ASCII to UNICODE (UTF-8)
• This is quite significant because it will be possible that
non-English characters can be used as identifiers,
which contain names of variables, functions, classes
and methods. Here are examples:
>>>印 = print
>>>範圍= range
>>> 甲 = 100
>>> 某數 = 甲 - 10
11
An exception for translation:
Python Keywords
are NOT translated
12
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True',
'and', 'as', 'assert', 'break', 'class', 'continue', 'def',
'del', 'elif', 'else', 'except', 'finally', 'for', 'from',
'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal',
'not', 'or', 'pass', 'raise', 'return', 'try', 'while',
'with', 'yield']
• Python keywords are usually common seen, short
English functional words, not used as identifiers
– The number of them is about 30, quite few!
A short example of Python in Kanji (漢字)
13
>>> 印= print
>>> 範圍= range
>>> 某字串= '你好,世界。'
>>> 重複的次數= 10
>>> for 數 in 範圍(重複的次數):
印(某字串, 數)
你好,世界。 0
你好,世界。 1
你好,世界。 2
你好,世界。 3
你好,世界。 4
你好,世界。 5
你好,世界。 6
你好,世界。 7
你好,世界。 8
你好,世界。 9
>>>
>>> 印刷= print
>>> 範囲= range
>>> 文字列= 'こんにちは世界!'
>>> 繰り返し数= 10
>>> for 数 in 範囲(繰り返し数):
印刷(文字列, 数)
こんにちは世界! 0
こんにちは世界! 1
こんにちは世界! 2
こんにちは世界! 3
こんにちは世界! 4
こんにちは世界! 5
こんにちは世界! 6
こんにちは世界! 7
こんにちは世界! 8
こんにちは世界! 9
>>>
A longer example
• An example to find
prime numbers within
100.
• It can be read aloud,
like a normal Chinese
article.
14
'''
prime100.py
本程式可以列出 100 以內的質數。
作者: 呂仁園,2015/03/04
'''
# 內建函數取中文別名
印= print
範圍= range
# 自定函數由此開始
def 主程式():
質數列= []
for 某數 in 範圍(2,101):
if 某數為質數(某數):
質數列 += [某數]
印('質數列= ',質數列)
def 甲整除乙(甲, 乙):
if 甲%乙 == 0:
return True
else:
return False
def 某數為質數(x):
答案= True
# 這是大膽假設,以下為小心求證
for n in 範圍(2, x):
if 甲整除乙(x, n):
答案= False #答案在此逆轉
break
return 答案 # 此為 True 或者 False
# 開始執行
主程式()
>>>
質數列= [2, 3, 5, 7, 11, 13,
17, 19, 23, 29, 31, 37, 41,
43, 47, 53, 59, 61, 67, 71,
73, 79, 83, 89, 97]
>>>
Python Module for Turtle Graphics
• Turtle graphics is a term in computer graphics
– [http://en.wikipedia.org/wiki/Turtle_graphics]
– part of the original Logo programming language
– by Wally Feurzig and Seymour Papert in 1966.
• The Python Turtle module is an extended
reimplementation
• from the Python standard distribution since Python 2.5.
15
Turtle Demo in IDLE Shell
• Starting from Python 3.4.2, a set of 18 turtle
demo programs was promoted to appear in
the main menu of IDLE Shell, just below
Python Docs within the Help sub-memu.
16
A typical example
• An example from the set of turtle demo programs: yinyang.py
17
陰
陽
Program
Translation
from turtle import * from turtle_tc import *
def yin(radius, color1, color2): def 陰(半徑, 顏色1, 顏色2):
width(3) 筆寬(3)
color("black", color1) 顏色(黑, 顏色1)
begin_fill() 開始填()
circle(radius/2., 180) 畫圓(半徑/2., 180)
circle(radius, 180) 畫圓(半徑, 180)
left(180) 左轉(180)
circle(-radius/2., 180) 畫圓(-半徑/2., 180)
end_fill() 結束填()
left(90) 左轉(90)
up() 提筆()
forward(radius*0.35) 前進(半徑*0.35)
right(90) 右轉(90)
down() 下筆()
color(color1, color2) 顏色(顏色1, 顏色2)
begin_fill() 開始填()
circle(radius*0.15) 畫圓(半徑*0.15)
end_fill() 結束填()
left(90) 左轉(90)
up() 提筆()
backward(radius*0.35) 後退(半徑*0.35)
down() 下筆()
left(90) 左轉(90)
def main(): def 主函數():
reset() 重設()
yin(200, "black", "white") 陰(200, 黑, 白)
yin(200, "white", "black") 陰(200, 白, 黑)
ht() 藏龜()
return "Done!" return "完成!"
if __name__ == '__main__': if __name__ == '__main__':
main() 主函數()
mainloop() 主迴圈()
18
• Is that possible we
translate those
beautiful and well-
coded programs?
• The Chinese programs
are obviously more
readable for those who
speak Chinese as their
native language.
Readability counts
• Anybody remember this Python’s Zen (禪)?
19
>>> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
...
...
>>>
If Readability really counts,…
• Then, what can be more readable to write
programs in your own native language, if the
readers are those who use the same language,
including myself, who read the programs the
most frequently!
20
Translation of the whole set
of 18 Turtle Demo programs
21
The File list of the whole set
of 18 programs
File path @ Windows
Line
number
C:Python34Libturtledemobytedesign.py 163
C:Python34Libturtledemochaos.py 60
C:Python34Libturtledemoclock.py 133
C:Python34Libturtledemocolormixer.py 59
C:Python34Libturtledemoforest.py 109
C:Python34Libturtledemofractalcurves.py 139
C:Python34Libturtledemolindenmayer.py 120
C:Python34Libturtledemominimal_hanoi.py 80
C:Python34Libturtledemonim.py 227
C:Python34Libturtledemopaint.py 55
C:Python34Libturtledemopeace.py 62
C:Python34Libturtledemopenrose.py 182
C:Python34Libturtledemoplanet_and_moon.py 113
C:Python34Libturtledemoround_dance.py 87
C:Python34Libturtledemotree.py 64
C:Python34Libturtledemotwo_canvases.py 55
C:Python34Libturtledemowikipedia.py 66
C:Python34Libturtledemoyinyang.py 50
Total line number 1824 22
23
18 programs
Inside the turtle module (turtle.py)
• The class diagram of the turtle module
24
class
_Screen
class
Turtle
25
An analogy to the Scratch language (originated from MIT)
Python
Turtle
Scratch
class
Turtle
Sprite
(貓精靈)
class
_Screen
Stage
(舞台)
• A simplified class diagram
26
Summary of the turtle module
• File path (@ Windows) C:Python34Libturtle.py
• Number of lines in source code
– About 4000 lines
– Rank 2 out of 160 python files in the standard library (Python 3.4.2)
• 2 major classes
• With the other 8 supporting classes
– class Turtle
• 80 methods
• E.g., forward , backward , left , right , …
– class _Screen
• 34 methods
• E.g., addshape, bgcolor, bgpic, clearscreen, …
• 112 Top-level functions
– All methods from class Turtle and class _Screen are redefine as the
top-level functions with a default turtle and screen objects
27
Diving into turtle.py
improve my Python skills
significantly!!
Alias of the turtle module
in Traditional Chinese (tc, or zh-tw)
• Upon the original turtle module, turtle.py, we
create an associated module called
turtle_tc.py, which provides the alias in
traditional Chinese (thus the subscript “_tc” )
for almost all identifiers (names) in turtle.py
28
DownLoad @ http://github.com/renyuanL/pythonTurtleInChinese
29
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06)
[MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> dir()
['__builtins__', '__doc__', '__loader__', '__name__',
'__package__', '__spec__']
>>> len(dir())
6
Step 1: start an IDLE session
Let’s have some overview
about turtle.py and turtle_tc.py
30
>>> from turtle import *
>>> dir()
['Pen', 'RawPen', 'RawTurtle', 'Screen', 'ScrolledCanvas', 'Shape', 'Terminator',
'Turtle', 'TurtleScreen', 'Vec2D', '__builtins__', '__doc__', '__loader__',
'__name__', '__package__', '__spec__', 'addshape', 'back', 'backward', 'begin_fill',
'begin_poly', 'bgcolor', 'bgpic', 'bk', 'bye', 'circle', 'clear', 'clearscreen',
'clearstamp', 'clearstamps', 'clone', 'color', 'colormode', 'degrees', 'delay',
'distance', 'done', 'dot', 'down', 'end_fill', 'end_poly', 'exitonclick', 'fd',
'fillcolor', 'filling', 'forward', 'get_poly', 'get_shapepoly', 'getcanvas',
'getpen', 'getscreen', 'getshapes', 'getturtle', 'goto', 'heading', 'hideturtle',
'home', 'ht', 'isdown', 'isvisible', 'left', 'listen', 'lt', 'mainloop', 'mode',
'numinput', 'onclick', 'ondrag', 'onkey', 'onkeypress', 'onkeyrelease', 'onrelease',
'onscreenclick', 'ontimer', 'pd', 'pen', 'pencolor', 'pendown', 'pensize', 'penup',
'pos', 'position', 'pu', 'radians', 'register_shape', 'reset', 'resetscreen',
'resizemode', 'right', 'rt', 'screensize', 'seth', 'setheading', 'setpos',
'setposition', 'settiltangle', 'setundobuffer', 'setup', 'setworldcoordinates',
'setx', 'sety', 'shape', 'shapesize', 'shapetransform', 'shearfactor', 'showturtle',
'speed', 'st', 'stamp', 'textinput', 'tilt', 'tiltangle', 'title', 'towards',
'tracer', 'turtles', 'turtlesize', 'undo', 'undobufferentries', 'up', 'update',
'width', 'window_height', 'window_width', 'write', 'write_docstringdict', 'xcor',
'ycor']
>>> len(dir())
128
Step 2: import turtle
128-6 == 122, turtle added
31
>>> from turtle_tc import *
>>> dir()
['Pen', 'RawPen', 'RawTurtle', 'Screen', 'ScrolledCanvas', 'Shape', 'TK', 'Terminator', 'Turtle', 'TurtleScreen', 'Vec2D',
'__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'addshape', 'back', 'backward', 'begin_fill',
'begin_poly', 'bgcolor', 'bgpic', 'bk', 'bye', 'circle', 'clear', 'clearscreen', 'clearstamp', 'clearstamps', 'clone', 'color',
'colormode', 'degrees', 'delay', 'distance', 'done', 'dot', 'down', 'end_fill', 'end_poly', 'exitonclick', 'fd', 'fillcolor',
'filling', 'forward', 'get_poly', 'get_shapepoly', 'getcanvas', 'getpen', 'getscreen', 'getshapes', 'getturtle', 'goto', 'heading',
'hideturtle', 'home', 'ht', 'isdown', 'isvisible', 'left', 'listen', 'lt', 'mainloop', 'mode', 'numinput', 'onclick', 'ondrag',
'onkey', 'onkeypress', 'onkeyrelease', 'onrelease', 'onscreenclick', 'ontimer', 'pd', 'pen', 'pencolor', 'pendown', 'pensize',
'penup', 'pos', 'position', 'pu', 'radians', 'register_shape', 'reset', 'resetscreen', 'resizemode', 'right', 'rt', 'screensize',
'seth', 'setheading', 'setpos', 'setposition', 'settiltangle', 'setundobuffer', 'setup', 'setworldcoordinates', 'setx', 'sety',
'shape', 'shapesize', 'shapetransform', 'shearfactor', 'showturtle', 'speed', 'st', 'stamp', 'textinput', 'tilt', 'tiltangle',
'title', 'towards', 'tracer', 'turtles', 'turtlesize', 'undo', 'undobufferentries', 'up', 'update', 'width', 'window_height',
'window_width', 'write', 'write_docstringdict', 'xcor', 'x座標', 'ycor', 'y座標', '下筆', '下筆嗎', '下筆狀態', '中英對照表', '主迴圈', '
亂取樣', '亂整數', '亂數', '亂選', '二維向量類', '位置', '假', '做完了', '傾斜', '傾斜角度', '再見', '前往', '前進', '加形狀', '半徑數', '印', '
原生筆類', '原生龜類', '去到', '取回復暫存區的長度', '取多邊形', '取幕', '取幕寬', '取幕高', '取形', '取形狀', '取形狀多邊形', '取時間', '取畫布',
'取筆', '取龜', '取龜列表', '可捲畫布類', '可見狀態', '右轉', '向上鍵', '向下鍵', '向右鍵', '向左鍵', '向量2D類', '向量類', '回家', '回家鍵', '回
復', '回復暫存區的個數', '回復暫存區的長度', '圓', '在幕點擊時', '在拖曳時', '在按下鍵時', '在按著鍵時', '在按鍵時', '在按鍵鬆開時', '在滑鼠拖曳龜時
', '在滑鼠釋放龜時', '在滑鼠鍵點擊幕時', '在滑鼠鍵點擊時', '在滑鼠鬆開龜時', '在滑鼠點擊龜時', '在計時器若干毫秒之後', '在計時後', '在釋放時', '在鬆
開時', '在點擊幕時', '在點擊時', '在點擊時離開', '在點擊龜時', '填色', '填色狀態', '大小', '寫', '寬', '左轉', '幕大小', '幕寬', '幕類', '幕高',
'座標x', '座標y', '座標系統', '延遲', '弧度', '弳度', '形', '形狀', '形狀大小', '形狀轉換', '形狀類', '後退', '戳印', '扭曲因子', '提筆', '方形
', '是否下筆', '是否可見', '是否正在填色', '時間', '更新', '更新畫面', '朝向', '朝向xy', '標題', '模式', '橙', '橙色', '正在填色', '清除', '清除
幕', '清除蓋章', '清除蓋章群', '清除鍵', '灰', '灰色', '烏龜形狀', '無', '生一隻龜', '生龜', '畫圓', '畫點', '登記形狀', '白', '白色', '看時間',
'真', '睡', '空白鍵', '窗寬', '窗高', '筆', '筆大小', '筆寬', '筆屬性', '筆粗', '筆粗細', '筆色', '筆類', '等待閉幕', '等時間', '範圍', '紅', '
紅色', '紫', '紫色', '結束填', '結束填色', '結束多邊形', '綠', '綠色', '聽', '聽鍵盤', '背景圖', '背景色', '脫離鍵', '色模式', '蓋印', '蓋章', '
藍', '藍色', '藏', '藏龜', '複製', '角度', '角度從北開始順時針', '設x座標', '設y座標', '設位置', '設傾斜角度', '設傾角', '設取扭曲因子', '設回復暫
存區', '設圓為2pi弧', '設圓為360度', '設座標x', '設座標y', '設座標系統', '設成可伸縮模式', '設標題', '設立', '設角為度', '設角為弧', '設角的單位為
半徑數', '設角的單位為角度', '設頭向', '註冊形狀', '距離', '輸入數字', '輸入文字', '追蹤', '追蹤器', '追蹤更新畫面', '速度', '進入主迴圈', '重設',
'重設大小模式', '重設幕', '重設幕大小', '重設幕寬高', '重設所有龜', '閉幕', '開始填', '開始填色', '開始多邊形', '開幕', '隨機取樣', '隨機整數', '隨
機數', '隨機選', '隱藏', '離開在點擊時', '青', '青色', '頭向', '顏色', '顯', '顯示', '顯龜', '顯龜嗎', '黃', '黃色', '黑', '黑色', '點', '點擊X
結束', '龜列表', '龜大小', '龜幕基類', '龜幕類', '龜形', '龜筆類', '龜群', '龜行類', '龜類']
>>> len(dir())
368
Step 3: after downloading turtle_tc, import it
368-128 == 240 , turtle_tc added
Let’s jump into turtle_tc.py
for more detail
32
Alias identifiers
龜幕基類= TurtleScreenBase
烏龜螢幕地基類= TurtleScreenBase
龜幕類= TurtleScreen
烏龜螢幕類= TurtleScreen
龜行類= TNavigator
烏龜航行類= TNavigator
龜筆類= TPen
烏龜畫筆類= TPen
原龜類= RawTurtle
粗龜類= RawTurtle
原生龜類= RawTurtle
_幕類= _Screen
_螢幕類= _Screen
幕類= Screen
螢幕類= Screen
開幕= Screen
龜類= Turtle
烏龜類= Turtle
33
class
TurtleScreen(TurtleScreenBase):
加形狀= addshape
背景色= bgcolor
背景圖= bgpic
清除= clear
清除幕= clearscreen
色模式= colormode
延遲= delay
取畫布= getcanvas
:
:
class TPen(object):
筆粗= pensize
筆粗細= pensize
筆大小= pensize
筆寬= width
寬= width
提筆= penup
下筆= pendown
:
class
TNavigator(object):
重設= reset
前進= forward
後退= back
右轉= right
左轉= left
位置= pos
前往= goto
:
• A partial list of the alias identifiers in turtle_tc.py
def x座標(): ...
def y座標(): ...
def 下筆(): ...
def 下筆嗎(): ...
def 下筆狀態(): ...
def 位置(): ...
def 傾斜(): ...
def 傾斜角度(): ...
def 前往(): ...
def 前進(): ...
def 半徑數(): ...
def 去到(): ...
def 點(): ...
def 龜大小(): ...
34
def 主迴圈(): ...
def 做完了(): ...
def 再見(): ...
def 加形狀(): ...
def 取幕寬(): ...
def 取幕高(): ...
def 取形(): ...
def 取形狀(): ...
def 取畫布(): ...
def 取龜列表(): ...
def 在幕點擊時(): ...
def 重設所有龜(): ...
def 閉幕(): ...
def 離開在點擊時(): ...
def 點擊X結束(): ...
def 龜列表(): ...
def 龜群(): ...
• A partial list of the alias identifiers
of top-level functions within turtle_tc.py
35
Aliasing In Class-level
(Hacking the source code??)
36
Aliasing in method level
(within class)
(Hacking the source code??)
37
Automatic code generation
• In turtle_tc.py, the aliasing procedure was not
hard coded manually, but an automatic code
generation mechanism was adopted.
• The only thing we have to do is to translate all
the names and keep them as an external file.
• This makes it more convenient to transfer
into another language.
38
ey= eval(y)
aClass= ip.getsource(ey)
cList= 'cList'+y
ec= eval(cList)
aClassL=[]
bClassL=[]
cClassL=[]
print(aClass)
for x in ec[1:]:
for n in range(1,len(x)):
bClass= ' '*4+x[n]+'= '+x[0]+'n'
#
# 物類 內, 有 4 個空白
#
aClass+= bClass
bClassL+= [bClass]
print(aClass)
exec(aClass)
cListTPen= [
('TPen', '龜筆類', '烏龜畫筆類'),
('pensize', '筆粗', '筆粗細', '筆大小'),
('width', '筆寬', '寬'),
('penup', '提筆'),
('pendown', '下筆'),
('showturtle', '顯龜','顯示','顯'),
('hideturtle', '藏龜','隱藏','藏'),
('color', '顏色'),
('pencolor', '筆色'),
('speed', '速度'),
('pen', '筆', '筆屬性'),
('fillcolor', '填色'),
y=
'Tpen’
ThetranslationfileAutomaticcodegeneration
Generatedcodetoberunonline
An extra important issue:
Providing on-line help
• A document file should also be provided to
on-line help available.
39
>>> help(前進)
Help on function 前進 in module turtle_tc:
前進(distance)
『0053 中文說明』
龜前進指定的距離。
別名: 前進 | forward | fd
參數:
距離, distance - 一個數字(整數或浮點數)
龜前進指定的距離, 往龜的頭之方向。
示例(物件名為「小龜」的實例):
>>> from turtle_tc import *
>>> 小龜= 龜類()
>>> 小龜.位置()
(0.00,0.00)
>>> 小龜.前進(25)
>>> 小龜.位置()
(25.00,0.00)
>>> 小龜.前進(-75)
>>> 小龜.位置()
(-50.00,0.00)
Demo
• On Youtube:
– http://youtu.be/sQFKjlxw2mw
• On NBViewer
– http://nbviewer.ipython.org/urls/dl.dropbox.com/
s/4n70b5e82cy74n4/tesing_turtle_tc.ipynb#
40
41
Submitted by eah13
1whoa I love the single-character self
3
我 (wo3) would probably be three keystrokes: two for "w" and "o",
then enter/spacebar to confirm substitution into the Chinese character.
7
me too. Japanese (two character) is pretty cool too: 自己 . I'm
thinking using characters would be a cool way to slim down a
programming language, a bit like how greek and russian characters
are used in math.
8
interestingly, that's self in chinese too. wo3 means I, while what you
wrote literally means self.
9I'm going to tattoo those Chinese characters on my arm.
An International Discussion Forum
about this Task
“A Python program written with 90% Traditional Chinese characters”
And more ....
http://www.reddit.com/r/Python/comments/268fts/a_python_program_written_with_90_traditional/
Conclusion
• We teach Reading, Writing, and Arithmetic to
kids in our native or official languages,
• which are usually not English in many countries
– E.g., in the APAC area.
• Why not try to teach kids programming
• in the same language with which they have been natively
familiar.
42
Reference
• [1] The whole set of 18 turtle demo programs
• https://github.com/renyuanL/pythonTurtleInChinese/tr
ee/master/tcExamples
• [2] Demo on youtube
• http://youtu.be/sQFKjlxw2mw
• [3] GitHub
• https://github.com/renyuanL/pythonTurtleInChinese
• [4] A Discussion Forum about this Task
• “A Python program written with 90%
Traditional Chinese characters”
– http://www.reddit.com/r/Python/comments/268fts/a_python_program_writ
ten_with_90_traditional/ 43
44
PyCon JP 2015
Renyuan Lyu
呂仁園
Thank you for Listening.
ご清聴 有り難う 御座いました。
真心 感謝 您的收聽。
Yunghsin Kuo
郭詠欣
Translation of Python Programs
into non-English Languages
for Learners without English Proficiency
Oct/11/日曜日 3:35 p.m.–4:05 p.m. in メディアホール/Media Hall
Visit my Blog for more Info
http://apython.blogspot.tw/

Weitere ähnliche Inhalte

Was ist angesagt?

PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and More
Matt Harrison
 

Was ist angesagt? (20)

2016 bioinformatics i_python_part_2_strings_wim_vancriekinge
2016 bioinformatics i_python_part_2_strings_wim_vancriekinge2016 bioinformatics i_python_part_2_strings_wim_vancriekinge
2016 bioinformatics i_python_part_2_strings_wim_vancriekinge
 
Python for Linux System Administration
Python for Linux System AdministrationPython for Linux System Administration
Python for Linux System Administration
 
Learning Python from Data
Learning Python from DataLearning Python from Data
Learning Python from Data
 
The Benefits of Type Hints
The Benefits of Type HintsThe Benefits of Type Hints
The Benefits of Type Hints
 
Python Workshop
Python WorkshopPython Workshop
Python Workshop
 
Introduction to Programming in Go
Introduction to Programming in GoIntroduction to Programming in Go
Introduction to Programming in Go
 
Learn python – for beginners
Learn python – for beginnersLearn python – for beginners
Learn python – for beginners
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Python basics_ part1
Python basics_ part1Python basics_ part1
Python basics_ part1
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and More
 
2016 bioinformatics i_python_part_1_wim_vancriekinge
2016 bioinformatics i_python_part_1_wim_vancriekinge2016 bioinformatics i_python_part_1_wim_vancriekinge
2016 bioinformatics i_python_part_1_wim_vancriekinge
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Python ppt
Python pptPython ppt
Python ppt
 
Programming with Python - Adv.
Programming with Python - Adv.Programming with Python - Adv.
Programming with Python - Adv.
 
Python final ppt
Python final pptPython final ppt
Python final ppt
 
Why Python (for Statisticians)
Why Python (for Statisticians)Why Python (for Statisticians)
Why Python (for Statisticians)
 
Introduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data Analytics
 
Using SWIG to Control, Prototype, and Debug C Programs with Python
Using SWIG to Control, Prototype, and Debug C Programs with PythonUsing SWIG to Control, Prototype, and Debug C Programs with Python
Using SWIG to Control, Prototype, and Debug C Programs with Python
 
Introduction to python 3 2nd round
Introduction to python 3   2nd roundIntroduction to python 3   2nd round
Introduction to python 3 2nd round
 

Andere mochten auch

Sphinxで作る貢献しやすい ドキュメント翻訳の仕組み
Sphinxで作る貢献しやすいドキュメント翻訳の仕組みSphinxで作る貢献しやすいドキュメント翻訳の仕組み
Sphinxで作る貢献しやすい ドキュメント翻訳の仕組み
Takayuki Shimizukawa
 

Andere mochten auch (20)

How we realized SOA by Python at PyCon JP 2015
How we realized SOA by Python at PyCon JP 2015How we realized SOA by Python at PyCon JP 2015
How we realized SOA by Python at PyCon JP 2015
 
PyCon JP 2015 keynote
PyCon JP 2015 keynotePyCon JP 2015 keynote
PyCon JP 2015 keynote
 
Pythonで作る俺様サウンドエフェクター
Pythonで作る俺様サウンドエフェクターPythonで作る俺様サウンドエフェクター
Pythonで作る俺様サウンドエフェクター
 
SekainoKAO by TeamKAO
SekainoKAO by TeamKAOSekainoKAO by TeamKAO
SekainoKAO by TeamKAO
 
tse - Pythonによるテキスト整形ユーティリティ
tse - Pythonによるテキスト整形ユーティリティtse - Pythonによるテキスト整形ユーティリティ
tse - Pythonによるテキスト整形ユーティリティ
 
PyLadies Tokyo - 初心者向けPython体験ワークショップ開催の裏側
PyLadies Tokyo - 初心者向けPython体験ワークショップ開催の裏側PyLadies Tokyo - 初心者向けPython体験ワークショップ開催の裏側
PyLadies Tokyo - 初心者向けPython体験ワークショップ開催の裏側
 
Sphinxで作る貢献しやすい ドキュメント翻訳の仕組み
Sphinxで作る貢献しやすいドキュメント翻訳の仕組みSphinxで作る貢献しやすいドキュメント翻訳の仕組み
Sphinxで作る貢献しやすい ドキュメント翻訳の仕組み
 
Python と型ヒント (Type Hints)
Python と型ヒント (Type Hints)Python と型ヒント (Type Hints)
Python と型ヒント (Type Hints)
 
アドネットワークのデータ解析チームを支える技術
アドネットワークのデータ解析チームを支える技術アドネットワークのデータ解析チームを支える技術
アドネットワークのデータ解析チームを支える技術
 
組合せ最適化を体系的に知ってPythonで実行してみよう PyCon 2015
組合せ最適化を体系的に知ってPythonで実行してみよう PyCon 2015組合せ最適化を体系的に知ってPythonで実行してみよう PyCon 2015
組合せ最適化を体系的に知ってPythonで実行してみよう PyCon 2015
 
PythonとPyCoRAMでお手軽にFPGAシステムを開発してみよう
PythonとPyCoRAMでお手軽にFPGAシステムを開発してみようPythonとPyCoRAMでお手軽にFPGAシステムを開発してみよう
PythonとPyCoRAMでお手軽にFPGAシステムを開発してみよう
 
強くなるためのプログラミング -プログラミングに関する様々なコンテストとそのはじめ方-#pyconjp
強くなるためのプログラミング -プログラミングに関する様々なコンテストとそのはじめ方-#pyconjp強くなるためのプログラミング -プログラミングに関する様々なコンテストとそのはじめ方-#pyconjp
強くなるためのプログラミング -プログラミングに関する様々なコンテストとそのはじめ方-#pyconjp
 
野球Hack!~Pythonを用いたデータ分析と可視化 #pyconjp
野球Hack!~Pythonを用いたデータ分析と可視化 #pyconjp野球Hack!~Pythonを用いたデータ分析と可視化 #pyconjp
野球Hack!~Pythonを用いたデータ分析と可視化 #pyconjp
 
日本のオープンデータプラットフォームをPythonでつくる
日本のオープンデータプラットフォームをPythonでつくる日本のオープンデータプラットフォームをPythonでつくる
日本のオープンデータプラットフォームをPythonでつくる
 
7days war - Minecraft
7days war - Minecraft7days war - Minecraft
7days war - Minecraft
 
Clrh87 minecraftでのタートルのご紹介
Clrh87 minecraftでのタートルのご紹介Clrh87 minecraftでのタートルのご紹介
Clrh87 minecraftでのタートルのご紹介
 
【minecraft】レッド​ストーン回路赤石論理学【配布資料】
【minecraft】レッド​ストーン回路赤石論理学【配布資料】【minecraft】レッド​ストーン回路赤石論理学【配布資料】
【minecraft】レッド​ストーン回路赤石論理学【配布資料】
 
論理回路シミュレータ Logisim の使い方
論理回路シミュレータ Logisim の使い方論理回路シミュレータ Logisim の使い方
論理回路シミュレータ Logisim の使い方
 
マインクラフトでプログラミングを楽しむ
マインクラフトでプログラミングを楽しむマインクラフトでプログラミングを楽しむ
マインクラフトでプログラミングを楽しむ
 
Minecraft Modding入門
Minecraft Modding入門Minecraft Modding入門
Minecraft Modding入門
 

Ähnlich wie pyconjp2015_talk_Translation of Python Program__

Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
Chetan Giridhar
 
python-160403194316.pdf
python-160403194316.pdfpython-160403194316.pdf
python-160403194316.pdf
gmadhu8
 

Ähnlich wie pyconjp2015_talk_Translation of Python Program__ (20)

Ry pyconjp2015 turtle
Ry pyconjp2015 turtleRy pyconjp2015 turtle
Ry pyconjp2015 turtle
 
Mastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsMastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loops
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
 
ForLoops.pptx
ForLoops.pptxForLoops.pptx
ForLoops.pptx
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
 
2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
 
Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
 
python presntation 2.pptx
python presntation 2.pptxpython presntation 2.pptx
python presntation 2.pptx
 
Python ppt
Python pptPython ppt
Python ppt
 
Python basics
Python basicsPython basics
Python basics
 
Python
PythonPython
Python
 
Python week 2 2019 2020 for g10 by eng.osama ghandour
Python week 2 2019 2020 for g10 by eng.osama ghandourPython week 2 2019 2020 for g10 by eng.osama ghandour
Python week 2 2019 2020 for g10 by eng.osama ghandour
 
python-160403194316.pdf
python-160403194316.pdfpython-160403194316.pdf
python-160403194316.pdf
 
Charming python
Charming pythonCharming python
Charming python
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1
 

Mehr von Renyuan Lyu (9)

Py conjp2019 renyuanlyu_3
Py conjp2019 renyuanlyu_3Py conjp2019 renyuanlyu_3
Py conjp2019 renyuanlyu_3
 
Py conjp2019 renyuanlyu_3
Py conjp2019 renyuanlyu_3Py conjp2019 renyuanlyu_3
Py conjp2019 renyuanlyu_3
 
Py conjp2019 renyuanlyu_3
Py conjp2019 renyuanlyu_3Py conjp2019 renyuanlyu_3
Py conjp2019 renyuanlyu_3
 
Lightning talk01 docx
Lightning talk01 docxLightning talk01 docx
Lightning talk01 docx
 
Lightning talk01
Lightning talk01Lightning talk01
Lightning talk01
 
Pycon JP 2016 ---- Pitch Detection
Pycon JP 2016 ---- Pitch DetectionPycon JP 2016 ---- Pitch Detection
Pycon JP 2016 ---- Pitch Detection
 
pycon jp 2016 ---- CguTranslate
pycon jp 2016 ---- CguTranslatepycon jp 2016 ---- CguTranslate
pycon jp 2016 ---- CguTranslate
 
教青少年寫程式
教青少年寫程式教青少年寫程式
教青少年寫程式
 
Pycon apac 2014
Pycon apac 2014Pycon apac 2014
Pycon apac 2014
 

Kürzlich hochgeladen

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Kürzlich hochgeladen (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

pyconjp2015_talk_Translation of Python Program__

  • 1. 1 PyCon JP 2015 Renyuan Lyu 呂仁園 Yunghsin Kuo 郭詠欣 Translation of Python Programs into non-English Languages for Learners without English Proficiency Oct/11/日曜日 3:35 p.m.–4:05 p.m. in メディアホール/Media Hall Chang Gung Univ. Taiwan Visit my Blog for more Info http://apython.blogspot.tw/
  • 2. 2 Computer Programming for everybody! No matter Old or Young No matter Boys or Girls Picture from Pycon JP 2015 https://www.python.org/doc/essays/cp4e/ By Guido van Rossum
  • 3. 3 Computer Programming for everybody? As long as she/he knows the English language!
  • 4. 4 Is it possible that the English language is the first barrier for people to learn programming? In what language, you teach your kids the fundamental math or science?
  • 5. Python Turtle Graphics in Traditional Chinese (Kanji) 傳統漢字の Python 龜作圖 5 Also appeared on Pycon APAC 2015 without technical detail http://apython.blogspot.tw This slide is here
  • 6. 2 Main Points • Python Programming in non-English Language improves readability for non-native English speakers • A set of 18 Turtle Demo Programs were Translated into Traditional Chinese as an Example 6 The term “Traditional Chinese” in this presentation may sometimes be used interchangeably with “Kanji”.
  • 7. Abstract • A set of 18 turtle demo programs has been translated into traditional Chinese (tc) • as an example to show the possibility to write Python code conveniently in non-English language. • To improve code clarity and readability • for non-native English speakers, according to Python PEP 3131. • To attract more people to learn programming • who are considered as less English proficiency. • Providing a full list of tc alias (turtle_tc.py) • for the official python turtle module. • Github Availability 7http://github.com/renyuanL/pythonTurtleInChinese
  • 9. The motivation was partially from PEP 3131: "Supporting Non-ASCII Identifiers" • many people in the world not familiar with the English language – They’d like to define variables, functions and classes with names in their native languages • code clarity and maintainability of the code among speakers of that language improves. • Original from PEP 3131 : [https://www.python.org/dev/peps/pep-3131/] 9
  • 10. One Glance at Python Code in English v.s. in Kanji from turtle import * print("Hello, this is turtle graphics.") for i in range(100): forward(100) left(100) from turtle_tc import * 印("哈囉,這是龜作圖。") for i in 範圍(100): 前進(100) 左轉(100) 10 The first impression of this kind of program: SHORTER in length, more compact, and more readable, if you understand kanji (漢字).
  • 11. Ignition: UTF-8 as Source encoding • After version 3.0, the Python language has changed its source coding from ASCII to UNICODE (UTF-8) • This is quite significant because it will be possible that non-English characters can be used as identifiers, which contain names of variables, functions, classes and methods. Here are examples: >>>印 = print >>>範圍= range >>> 甲 = 100 >>> 某數 = 甲 - 10 11
  • 12. An exception for translation: Python Keywords are NOT translated 12 >>> import keyword >>> keyword.kwlist ['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'] • Python keywords are usually common seen, short English functional words, not used as identifiers – The number of them is about 30, quite few!
  • 13. A short example of Python in Kanji (漢字) 13 >>> 印= print >>> 範圍= range >>> 某字串= '你好,世界。' >>> 重複的次數= 10 >>> for 數 in 範圍(重複的次數): 印(某字串, 數) 你好,世界。 0 你好,世界。 1 你好,世界。 2 你好,世界。 3 你好,世界。 4 你好,世界。 5 你好,世界。 6 你好,世界。 7 你好,世界。 8 你好,世界。 9 >>> >>> 印刷= print >>> 範囲= range >>> 文字列= 'こんにちは世界!' >>> 繰り返し数= 10 >>> for 数 in 範囲(繰り返し数): 印刷(文字列, 数) こんにちは世界! 0 こんにちは世界! 1 こんにちは世界! 2 こんにちは世界! 3 こんにちは世界! 4 こんにちは世界! 5 こんにちは世界! 6 こんにちは世界! 7 こんにちは世界! 8 こんにちは世界! 9 >>>
  • 14. A longer example • An example to find prime numbers within 100. • It can be read aloud, like a normal Chinese article. 14 ''' prime100.py 本程式可以列出 100 以內的質數。 作者: 呂仁園,2015/03/04 ''' # 內建函數取中文別名 印= print 範圍= range # 自定函數由此開始 def 主程式(): 質數列= [] for 某數 in 範圍(2,101): if 某數為質數(某數): 質數列 += [某數] 印('質數列= ',質數列) def 甲整除乙(甲, 乙): if 甲%乙 == 0: return True else: return False def 某數為質數(x): 答案= True # 這是大膽假設,以下為小心求證 for n in 範圍(2, x): if 甲整除乙(x, n): 答案= False #答案在此逆轉 break return 答案 # 此為 True 或者 False # 開始執行 主程式() >>> 質數列= [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97] >>>
  • 15. Python Module for Turtle Graphics • Turtle graphics is a term in computer graphics – [http://en.wikipedia.org/wiki/Turtle_graphics] – part of the original Logo programming language – by Wally Feurzig and Seymour Papert in 1966. • The Python Turtle module is an extended reimplementation • from the Python standard distribution since Python 2.5. 15
  • 16. Turtle Demo in IDLE Shell • Starting from Python 3.4.2, a set of 18 turtle demo programs was promoted to appear in the main menu of IDLE Shell, just below Python Docs within the Help sub-memu. 16
  • 17. A typical example • An example from the set of turtle demo programs: yinyang.py 17 陰 陽
  • 18. Program Translation from turtle import * from turtle_tc import * def yin(radius, color1, color2): def 陰(半徑, 顏色1, 顏色2): width(3) 筆寬(3) color("black", color1) 顏色(黑, 顏色1) begin_fill() 開始填() circle(radius/2., 180) 畫圓(半徑/2., 180) circle(radius, 180) 畫圓(半徑, 180) left(180) 左轉(180) circle(-radius/2., 180) 畫圓(-半徑/2., 180) end_fill() 結束填() left(90) 左轉(90) up() 提筆() forward(radius*0.35) 前進(半徑*0.35) right(90) 右轉(90) down() 下筆() color(color1, color2) 顏色(顏色1, 顏色2) begin_fill() 開始填() circle(radius*0.15) 畫圓(半徑*0.15) end_fill() 結束填() left(90) 左轉(90) up() 提筆() backward(radius*0.35) 後退(半徑*0.35) down() 下筆() left(90) 左轉(90) def main(): def 主函數(): reset() 重設() yin(200, "black", "white") 陰(200, 黑, 白) yin(200, "white", "black") 陰(200, 白, 黑) ht() 藏龜() return "Done!" return "完成!" if __name__ == '__main__': if __name__ == '__main__': main() 主函數() mainloop() 主迴圈() 18 • Is that possible we translate those beautiful and well- coded programs? • The Chinese programs are obviously more readable for those who speak Chinese as their native language.
  • 19. Readability counts • Anybody remember this Python’s Zen (禪)? 19 >>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. ... ... >>>
  • 20. If Readability really counts,… • Then, what can be more readable to write programs in your own native language, if the readers are those who use the same language, including myself, who read the programs the most frequently! 20
  • 21. Translation of the whole set of 18 Turtle Demo programs 21
  • 22. The File list of the whole set of 18 programs File path @ Windows Line number C:Python34Libturtledemobytedesign.py 163 C:Python34Libturtledemochaos.py 60 C:Python34Libturtledemoclock.py 133 C:Python34Libturtledemocolormixer.py 59 C:Python34Libturtledemoforest.py 109 C:Python34Libturtledemofractalcurves.py 139 C:Python34Libturtledemolindenmayer.py 120 C:Python34Libturtledemominimal_hanoi.py 80 C:Python34Libturtledemonim.py 227 C:Python34Libturtledemopaint.py 55 C:Python34Libturtledemopeace.py 62 C:Python34Libturtledemopenrose.py 182 C:Python34Libturtledemoplanet_and_moon.py 113 C:Python34Libturtledemoround_dance.py 87 C:Python34Libturtledemotree.py 64 C:Python34Libturtledemotwo_canvases.py 55 C:Python34Libturtledemowikipedia.py 66 C:Python34Libturtledemoyinyang.py 50 Total line number 1824 22
  • 24. Inside the turtle module (turtle.py) • The class diagram of the turtle module 24 class _Screen class Turtle
  • 25. 25 An analogy to the Scratch language (originated from MIT) Python Turtle Scratch class Turtle Sprite (貓精靈) class _Screen Stage (舞台)
  • 26. • A simplified class diagram 26
  • 27. Summary of the turtle module • File path (@ Windows) C:Python34Libturtle.py • Number of lines in source code – About 4000 lines – Rank 2 out of 160 python files in the standard library (Python 3.4.2) • 2 major classes • With the other 8 supporting classes – class Turtle • 80 methods • E.g., forward , backward , left , right , … – class _Screen • 34 methods • E.g., addshape, bgcolor, bgpic, clearscreen, … • 112 Top-level functions – All methods from class Turtle and class _Screen are redefine as the top-level functions with a default turtle and screen objects 27 Diving into turtle.py improve my Python skills significantly!!
  • 28. Alias of the turtle module in Traditional Chinese (tc, or zh-tw) • Upon the original turtle module, turtle.py, we create an associated module called turtle_tc.py, which provides the alias in traditional Chinese (thus the subscript “_tc” ) for almost all identifiers (names) in turtle.py 28 DownLoad @ http://github.com/renyuanL/pythonTurtleInChinese
  • 29. 29 Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> dir() ['__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__'] >>> len(dir()) 6 Step 1: start an IDLE session Let’s have some overview about turtle.py and turtle_tc.py
  • 30. 30 >>> from turtle import * >>> dir() ['Pen', 'RawPen', 'RawTurtle', 'Screen', 'ScrolledCanvas', 'Shape', 'Terminator', 'Turtle', 'TurtleScreen', 'Vec2D', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'addshape', 'back', 'backward', 'begin_fill', 'begin_poly', 'bgcolor', 'bgpic', 'bk', 'bye', 'circle', 'clear', 'clearscreen', 'clearstamp', 'clearstamps', 'clone', 'color', 'colormode', 'degrees', 'delay', 'distance', 'done', 'dot', 'down', 'end_fill', 'end_poly', 'exitonclick', 'fd', 'fillcolor', 'filling', 'forward', 'get_poly', 'get_shapepoly', 'getcanvas', 'getpen', 'getscreen', 'getshapes', 'getturtle', 'goto', 'heading', 'hideturtle', 'home', 'ht', 'isdown', 'isvisible', 'left', 'listen', 'lt', 'mainloop', 'mode', 'numinput', 'onclick', 'ondrag', 'onkey', 'onkeypress', 'onkeyrelease', 'onrelease', 'onscreenclick', 'ontimer', 'pd', 'pen', 'pencolor', 'pendown', 'pensize', 'penup', 'pos', 'position', 'pu', 'radians', 'register_shape', 'reset', 'resetscreen', 'resizemode', 'right', 'rt', 'screensize', 'seth', 'setheading', 'setpos', 'setposition', 'settiltangle', 'setundobuffer', 'setup', 'setworldcoordinates', 'setx', 'sety', 'shape', 'shapesize', 'shapetransform', 'shearfactor', 'showturtle', 'speed', 'st', 'stamp', 'textinput', 'tilt', 'tiltangle', 'title', 'towards', 'tracer', 'turtles', 'turtlesize', 'undo', 'undobufferentries', 'up', 'update', 'width', 'window_height', 'window_width', 'write', 'write_docstringdict', 'xcor', 'ycor'] >>> len(dir()) 128 Step 2: import turtle 128-6 == 122, turtle added
  • 31. 31 >>> from turtle_tc import * >>> dir() ['Pen', 'RawPen', 'RawTurtle', 'Screen', 'ScrolledCanvas', 'Shape', 'TK', 'Terminator', 'Turtle', 'TurtleScreen', 'Vec2D', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'addshape', 'back', 'backward', 'begin_fill', 'begin_poly', 'bgcolor', 'bgpic', 'bk', 'bye', 'circle', 'clear', 'clearscreen', 'clearstamp', 'clearstamps', 'clone', 'color', 'colormode', 'degrees', 'delay', 'distance', 'done', 'dot', 'down', 'end_fill', 'end_poly', 'exitonclick', 'fd', 'fillcolor', 'filling', 'forward', 'get_poly', 'get_shapepoly', 'getcanvas', 'getpen', 'getscreen', 'getshapes', 'getturtle', 'goto', 'heading', 'hideturtle', 'home', 'ht', 'isdown', 'isvisible', 'left', 'listen', 'lt', 'mainloop', 'mode', 'numinput', 'onclick', 'ondrag', 'onkey', 'onkeypress', 'onkeyrelease', 'onrelease', 'onscreenclick', 'ontimer', 'pd', 'pen', 'pencolor', 'pendown', 'pensize', 'penup', 'pos', 'position', 'pu', 'radians', 'register_shape', 'reset', 'resetscreen', 'resizemode', 'right', 'rt', 'screensize', 'seth', 'setheading', 'setpos', 'setposition', 'settiltangle', 'setundobuffer', 'setup', 'setworldcoordinates', 'setx', 'sety', 'shape', 'shapesize', 'shapetransform', 'shearfactor', 'showturtle', 'speed', 'st', 'stamp', 'textinput', 'tilt', 'tiltangle', 'title', 'towards', 'tracer', 'turtles', 'turtlesize', 'undo', 'undobufferentries', 'up', 'update', 'width', 'window_height', 'window_width', 'write', 'write_docstringdict', 'xcor', 'x座標', 'ycor', 'y座標', '下筆', '下筆嗎', '下筆狀態', '中英對照表', '主迴圈', ' 亂取樣', '亂整數', '亂數', '亂選', '二維向量類', '位置', '假', '做完了', '傾斜', '傾斜角度', '再見', '前往', '前進', '加形狀', '半徑數', '印', ' 原生筆類', '原生龜類', '去到', '取回復暫存區的長度', '取多邊形', '取幕', '取幕寬', '取幕高', '取形', '取形狀', '取形狀多邊形', '取時間', '取畫布', '取筆', '取龜', '取龜列表', '可捲畫布類', '可見狀態', '右轉', '向上鍵', '向下鍵', '向右鍵', '向左鍵', '向量2D類', '向量類', '回家', '回家鍵', '回 復', '回復暫存區的個數', '回復暫存區的長度', '圓', '在幕點擊時', '在拖曳時', '在按下鍵時', '在按著鍵時', '在按鍵時', '在按鍵鬆開時', '在滑鼠拖曳龜時 ', '在滑鼠釋放龜時', '在滑鼠鍵點擊幕時', '在滑鼠鍵點擊時', '在滑鼠鬆開龜時', '在滑鼠點擊龜時', '在計時器若干毫秒之後', '在計時後', '在釋放時', '在鬆 開時', '在點擊幕時', '在點擊時', '在點擊時離開', '在點擊龜時', '填色', '填色狀態', '大小', '寫', '寬', '左轉', '幕大小', '幕寬', '幕類', '幕高', '座標x', '座標y', '座標系統', '延遲', '弧度', '弳度', '形', '形狀', '形狀大小', '形狀轉換', '形狀類', '後退', '戳印', '扭曲因子', '提筆', '方形 ', '是否下筆', '是否可見', '是否正在填色', '時間', '更新', '更新畫面', '朝向', '朝向xy', '標題', '模式', '橙', '橙色', '正在填色', '清除', '清除 幕', '清除蓋章', '清除蓋章群', '清除鍵', '灰', '灰色', '烏龜形狀', '無', '生一隻龜', '生龜', '畫圓', '畫點', '登記形狀', '白', '白色', '看時間', '真', '睡', '空白鍵', '窗寬', '窗高', '筆', '筆大小', '筆寬', '筆屬性', '筆粗', '筆粗細', '筆色', '筆類', '等待閉幕', '等時間', '範圍', '紅', ' 紅色', '紫', '紫色', '結束填', '結束填色', '結束多邊形', '綠', '綠色', '聽', '聽鍵盤', '背景圖', '背景色', '脫離鍵', '色模式', '蓋印', '蓋章', ' 藍', '藍色', '藏', '藏龜', '複製', '角度', '角度從北開始順時針', '設x座標', '設y座標', '設位置', '設傾斜角度', '設傾角', '設取扭曲因子', '設回復暫 存區', '設圓為2pi弧', '設圓為360度', '設座標x', '設座標y', '設座標系統', '設成可伸縮模式', '設標題', '設立', '設角為度', '設角為弧', '設角的單位為 半徑數', '設角的單位為角度', '設頭向', '註冊形狀', '距離', '輸入數字', '輸入文字', '追蹤', '追蹤器', '追蹤更新畫面', '速度', '進入主迴圈', '重設', '重設大小模式', '重設幕', '重設幕大小', '重設幕寬高', '重設所有龜', '閉幕', '開始填', '開始填色', '開始多邊形', '開幕', '隨機取樣', '隨機整數', '隨 機數', '隨機選', '隱藏', '離開在點擊時', '青', '青色', '頭向', '顏色', '顯', '顯示', '顯龜', '顯龜嗎', '黃', '黃色', '黑', '黑色', '點', '點擊X 結束', '龜列表', '龜大小', '龜幕基類', '龜幕類', '龜形', '龜筆類', '龜群', '龜行類', '龜類'] >>> len(dir()) 368 Step 3: after downloading turtle_tc, import it 368-128 == 240 , turtle_tc added
  • 32. Let’s jump into turtle_tc.py for more detail 32
  • 33. Alias identifiers 龜幕基類= TurtleScreenBase 烏龜螢幕地基類= TurtleScreenBase 龜幕類= TurtleScreen 烏龜螢幕類= TurtleScreen 龜行類= TNavigator 烏龜航行類= TNavigator 龜筆類= TPen 烏龜畫筆類= TPen 原龜類= RawTurtle 粗龜類= RawTurtle 原生龜類= RawTurtle _幕類= _Screen _螢幕類= _Screen 幕類= Screen 螢幕類= Screen 開幕= Screen 龜類= Turtle 烏龜類= Turtle 33 class TurtleScreen(TurtleScreenBase): 加形狀= addshape 背景色= bgcolor 背景圖= bgpic 清除= clear 清除幕= clearscreen 色模式= colormode 延遲= delay 取畫布= getcanvas : : class TPen(object): 筆粗= pensize 筆粗細= pensize 筆大小= pensize 筆寬= width 寬= width 提筆= penup 下筆= pendown : class TNavigator(object): 重設= reset 前進= forward 後退= back 右轉= right 左轉= left 位置= pos 前往= goto : • A partial list of the alias identifiers in turtle_tc.py
  • 34. def x座標(): ... def y座標(): ... def 下筆(): ... def 下筆嗎(): ... def 下筆狀態(): ... def 位置(): ... def 傾斜(): ... def 傾斜角度(): ... def 前往(): ... def 前進(): ... def 半徑數(): ... def 去到(): ... def 點(): ... def 龜大小(): ... 34 def 主迴圈(): ... def 做完了(): ... def 再見(): ... def 加形狀(): ... def 取幕寬(): ... def 取幕高(): ... def 取形(): ... def 取形狀(): ... def 取畫布(): ... def 取龜列表(): ... def 在幕點擊時(): ... def 重設所有龜(): ... def 閉幕(): ... def 離開在點擊時(): ... def 點擊X結束(): ... def 龜列表(): ... def 龜群(): ... • A partial list of the alias identifiers of top-level functions within turtle_tc.py
  • 36. 36 Aliasing in method level (within class) (Hacking the source code??)
  • 37. 37 Automatic code generation • In turtle_tc.py, the aliasing procedure was not hard coded manually, but an automatic code generation mechanism was adopted. • The only thing we have to do is to translate all the names and keep them as an external file. • This makes it more convenient to transfer into another language.
  • 38. 38 ey= eval(y) aClass= ip.getsource(ey) cList= 'cList'+y ec= eval(cList) aClassL=[] bClassL=[] cClassL=[] print(aClass) for x in ec[1:]: for n in range(1,len(x)): bClass= ' '*4+x[n]+'= '+x[0]+'n' # # 物類 內, 有 4 個空白 # aClass+= bClass bClassL+= [bClass] print(aClass) exec(aClass) cListTPen= [ ('TPen', '龜筆類', '烏龜畫筆類'), ('pensize', '筆粗', '筆粗細', '筆大小'), ('width', '筆寬', '寬'), ('penup', '提筆'), ('pendown', '下筆'), ('showturtle', '顯龜','顯示','顯'), ('hideturtle', '藏龜','隱藏','藏'), ('color', '顏色'), ('pencolor', '筆色'), ('speed', '速度'), ('pen', '筆', '筆屬性'), ('fillcolor', '填色'), y= 'Tpen’ ThetranslationfileAutomaticcodegeneration Generatedcodetoberunonline
  • 39. An extra important issue: Providing on-line help • A document file should also be provided to on-line help available. 39 >>> help(前進) Help on function 前進 in module turtle_tc: 前進(distance) 『0053 中文說明』 龜前進指定的距離。 別名: 前進 | forward | fd 參數: 距離, distance - 一個數字(整數或浮點數) 龜前進指定的距離, 往龜的頭之方向。 示例(物件名為「小龜」的實例): >>> from turtle_tc import * >>> 小龜= 龜類() >>> 小龜.位置() (0.00,0.00) >>> 小龜.前進(25) >>> 小龜.位置() (25.00,0.00) >>> 小龜.前進(-75) >>> 小龜.位置() (-50.00,0.00)
  • 40. Demo • On Youtube: – http://youtu.be/sQFKjlxw2mw • On NBViewer – http://nbviewer.ipython.org/urls/dl.dropbox.com/ s/4n70b5e82cy74n4/tesing_turtle_tc.ipynb# 40
  • 41. 41 Submitted by eah13 1whoa I love the single-character self 3 我 (wo3) would probably be three keystrokes: two for "w" and "o", then enter/spacebar to confirm substitution into the Chinese character. 7 me too. Japanese (two character) is pretty cool too: 自己 . I'm thinking using characters would be a cool way to slim down a programming language, a bit like how greek and russian characters are used in math. 8 interestingly, that's self in chinese too. wo3 means I, while what you wrote literally means self. 9I'm going to tattoo those Chinese characters on my arm. An International Discussion Forum about this Task “A Python program written with 90% Traditional Chinese characters” And more .... http://www.reddit.com/r/Python/comments/268fts/a_python_program_written_with_90_traditional/
  • 42. Conclusion • We teach Reading, Writing, and Arithmetic to kids in our native or official languages, • which are usually not English in many countries – E.g., in the APAC area. • Why not try to teach kids programming • in the same language with which they have been natively familiar. 42
  • 43. Reference • [1] The whole set of 18 turtle demo programs • https://github.com/renyuanL/pythonTurtleInChinese/tr ee/master/tcExamples • [2] Demo on youtube • http://youtu.be/sQFKjlxw2mw • [3] GitHub • https://github.com/renyuanL/pythonTurtleInChinese • [4] A Discussion Forum about this Task • “A Python program written with 90% Traditional Chinese characters” – http://www.reddit.com/r/Python/comments/268fts/a_python_program_writ ten_with_90_traditional/ 43
  • 44. 44 PyCon JP 2015 Renyuan Lyu 呂仁園 Thank you for Listening. ご清聴 有り難う 御座いました。 真心 感謝 您的收聽。 Yunghsin Kuo 郭詠欣 Translation of Python Programs into non-English Languages for Learners without English Proficiency Oct/11/日曜日 3:35 p.m.–4:05 p.m. in メディアホール/Media Hall Visit my Blog for more Info http://apython.blogspot.tw/