SlideShare a Scribd company logo
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/
Python Turtle Graphics
in Traditional Chinese (Kanji)
傳統漢字の Python 龜作圖
2
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
3
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
4http://github.com/renyuanL/pythonTurtleInChinese
5
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/]
6
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)
7
The first impression
of this kind of program:
SHORTER in length,
more compact,
and more readable,
if you understand kanji (漢字).
Ignition: UTF-8
used as Source encoding of Python 3.0
• 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
8
An exception for translation:
Python Keywords
are NOT translated
9
>>> 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, used for grammatical purposes.
– The number of them is about 30, quite few!
• This small set of words cannot be used as identifiers, with
the other considerations not mentioned here, they are left
as the original forms without translation.
A short example of Python in Kanji (漢字)
10
>>> 印= 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.
11
'''
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
• for a method of programming vector graphics using a
relative cursor (the "turtle") upon a Cartesian plane.
– [http://en.wikipedia.org/wiki/Turtle_graphics]
• It was part of the original Logo programming
language
• developed by Wally Feurzig and Seymour Papert in 1966.
– According to this, I find I am still younger than the Turtle 
• The turtle module is an extended reimplementation
• of the same-named module from the Python standard
distribution up to version Python 2.5.
12
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.
13
A typical example
• An example from the set of turtle demo programs: yinyang.py
14
陰
陽
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() 主迴圈()
15
• 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 (禪)?
16
>>> 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!
17
Translation of the whole set
of 18 Turtle Demo programs
18
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 19
20
18 programs
Inside the turtle module (turtle.py)
• The class diagram of the turtle module
21
class
_Screen
class
Turtle
22
An analogy to the Scratch language (originated from MIT)
Python
Turtle
Scratch
class
Turtle
Sprite
(貓精靈)
class
_Screen
Stage
(舞台)
• A simplified class diagram
23
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
24
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
25
DownLoad @ http://github.com/renyuanL/pythonTurtleInChinese
26
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
27
>>> 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
28
>>> 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
29
Alias identifiers
龜幕基類= TurtleScreenBase
烏龜螢幕地基類= TurtleScreenBase
龜幕類= TurtleScreen
烏龜螢幕類= TurtleScreen
龜行類= TNavigator
烏龜航行類= TNavigator
龜筆類= TPen
烏龜畫筆類= TPen
原龜類= RawTurtle
粗龜類= RawTurtle
原生龜類= RawTurtle
_幕類= _Screen
_螢幕類= _Screen
幕類= Screen
螢幕類= Screen
開幕= Screen
龜類= Turtle
烏龜類= Turtle
30
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 龜大小(): ...
31
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
32
Aliasing In Class-level
(Hacking the source code??)
33
Aliasing in method level
(within class)
(Hacking the source code??)
34
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.
35
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.
36
>>> 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#
37
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.
38
Thinking in English? or in native language !
How many of you can memorize and read out
aloud the multiplication table in English, if your
educational language in school is not English?
Reference
• [1] The whole set of 18 turtle demo programs
– https://github.com/renyuanL/pythonTurtleInChinese/tree/mast
er/tcExamples
– Demo on youtube
• http://youtu.be/sQFKjlxw2mw
• [2] renyuanL/pythonTurtleInChinese
– https://github.com/renyuanL/pythonTurtleInChinese
• [3] ChinesePython
– http://www.chinesepython.org/
• [4] Zhpy
– https://code.google.com/p/zhpy/
• [5] Computer Programming for Everybody
– https://www.python.org/doc/essays/cp4e/
• [6] PEP 3131 - Supporting Non-ASCII Identifiers
– https://www.python.org/dev/peps/pep-3131/
39
40
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/

More Related Content

What's hot (20)

PDF
Pydiomatic
rik0
 
PDF
Python basic
Saifuddin Kaijar
 
PDF
Python programming Workshop SITTTR - Kalamassery
SHAMJITH KM
 
PPTX
Python ppt
Anush verma
 
PPTX
Python Basics
Adheetha O. V
 
PDF
Erlang
HyeonSeok Choi
 
PPTX
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
PDF
Go Java, Go!
Andres Almiray
 
PDF
Introduction to advanced python
Charles-Axel Dein
 
PPTX
Go Java, Go!
Andres Almiray
 
PPTX
Python basics
Manisha Gholve
 
PPTX
Python
Gagandeep Nanda
 
PPTX
Learn Python The Hard Way Presentation
Amira ElSharkawy
 
PDF
Let’s Learn Python An introduction to Python
Jaganadh Gopinadhan
 
PDF
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
PDF
Python Tutorial
AkramWaseem
 
PPTX
Introduction to Python programming
Damian T. Gordon
 
PPTX
Python basics
Hoang Nguyen
 
PPTX
Introduction to the basics of Python programming (part 3)
Pedro Rodrigues
 
Pydiomatic
rik0
 
Python basic
Saifuddin Kaijar
 
Python programming Workshop SITTTR - Kalamassery
SHAMJITH KM
 
Python ppt
Anush verma
 
Python Basics
Adheetha O. V
 
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
Go Java, Go!
Andres Almiray
 
Introduction to advanced python
Charles-Axel Dein
 
Go Java, Go!
Andres Almiray
 
Python basics
Manisha Gholve
 
Learn Python The Hard Way Presentation
Amira ElSharkawy
 
Let’s Learn Python An introduction to Python
Jaganadh Gopinadhan
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
Python Tutorial
AkramWaseem
 
Introduction to Python programming
Damian T. Gordon
 
Python basics
Hoang Nguyen
 
Introduction to the basics of Python programming (part 3)
Pedro Rodrigues
 

Similar to Ry pyconjp2015 turtle (20)

PDF
pyconjp2015_talk_Translation of Python Program__
Renyuan Lyu
 
PPTX
Keep it Stupidly Simple Introduce Python
SushJalai
 
PPTX
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
PPTX
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
PPTX
Python knowledge ,......................
sabith777a
 
PPTX
Introduction to learn and Python Interpreter
Alamelu
 
PPTX
Chapter1 python introduction syntax general
ssuser77162c
 
PPTX
Python basics
RANAALIMAJEEDRAJPUT
 
PPTX
Python basics
Young Alista
 
PPTX
Python basics
Luis Goldster
 
PPTX
Python basics
Harry Potter
 
PPTX
Python basics
Fraboni Ec
 
PPTX
Python basics
James Wong
 
PPTX
Python basics
Tony Nguyen
 
PPT
uso del lenguaje de programación python en métodos numéricos..ppt
angelca13
 
PPT
Learn Python in three hours - Python is an experiment
Anil Yadav
 
PPT
Python doc and Learn Python in three hours
Anil Yadav
 
PPT
python_presentation_for students_high_school
RakeshKumar483087
 
PPT
python programing 101 presentation ... Let's start
Mohsen Hefni
 
pyconjp2015_talk_Translation of Python Program__
Renyuan Lyu
 
Keep it Stupidly Simple Introduce Python
SushJalai
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
 
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
Python knowledge ,......................
sabith777a
 
Introduction to learn and Python Interpreter
Alamelu
 
Chapter1 python introduction syntax general
ssuser77162c
 
Python basics
RANAALIMAJEEDRAJPUT
 
Python basics
Young Alista
 
Python basics
Luis Goldster
 
Python basics
Harry Potter
 
Python basics
Fraboni Ec
 
Python basics
James Wong
 
Python basics
Tony Nguyen
 
uso del lenguaje de programación python en métodos numéricos..ppt
angelca13
 
Learn Python in three hours - Python is an experiment
Anil Yadav
 
Python doc and Learn Python in three hours
Anil Yadav
 
python_presentation_for students_high_school
RakeshKumar483087
 
python programing 101 presentation ... Let's start
Mohsen Hefni
 
Ad

More from Renyuan Lyu (10)

PDF
Py conjp2019 renyuanlyu_3
Renyuan Lyu
 
PPTX
Py conjp2019 renyuanlyu_3
Renyuan Lyu
 
PDF
Py conjp2019 renyuanlyu_3
Renyuan Lyu
 
PDF
Lightning talk01 docx
Renyuan Lyu
 
PDF
Lightning talk01
Renyuan Lyu
 
PPTX
Pycon JP 2016 ---- Pitch Detection
Renyuan Lyu
 
PPTX
pycon jp 2016 ---- CguTranslate
Renyuan Lyu
 
PDF
Ry pyconjp2015 karaoke
Renyuan Lyu
 
PDF
教青少年寫程式
Renyuan Lyu
 
PDF
Pycon apac 2014
Renyuan Lyu
 
Py conjp2019 renyuanlyu_3
Renyuan Lyu
 
Py conjp2019 renyuanlyu_3
Renyuan Lyu
 
Py conjp2019 renyuanlyu_3
Renyuan Lyu
 
Lightning talk01 docx
Renyuan Lyu
 
Lightning talk01
Renyuan Lyu
 
Pycon JP 2016 ---- Pitch Detection
Renyuan Lyu
 
pycon jp 2016 ---- CguTranslate
Renyuan Lyu
 
Ry pyconjp2015 karaoke
Renyuan Lyu
 
教青少年寫程式
Renyuan Lyu
 
Pycon apac 2014
Renyuan Lyu
 
Ad

Recently uploaded (20)

PPTX
Orientation MOOCs on SWAYAM for Teachers
moocs1
 
PPTX
HERNIA: INGUINAL HERNIA, UMBLICAL HERNIA.pptx
PRADEEP ABOTHU
 
PDF
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PDF
Exploring-the-Investigative-World-of-Science.pdf/8th class curiosity/1st chap...
Sandeep Swamy
 
PPTX
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
PPTX
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
PDF
Module 1: Determinants of Health [Tutorial Slides]
JonathanHallett4
 
PPTX
VOMITINGS - NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PPTX
INTESTINAL OBSTRUCTION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PPTX
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
PPTX
Joint Mobility : Fundamentals of Joint Mobility
Sreeraj S R
 
PPTX
GENERAL METHODS OF ISOLATION AND PURIFICATION OF MARINE__MPHARM.pptx
SHAHEEN SHABBIR
 
PPTX
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PDF
FULL DOCUMENT: Read the full Deloitte and Touche audit report on the National...
Kweku Zurek
 
PPTX
Constitutional Design Civics Class 9.pptx
bikesh692
 
Orientation MOOCs on SWAYAM for Teachers
moocs1
 
HERNIA: INGUINAL HERNIA, UMBLICAL HERNIA.pptx
PRADEEP ABOTHU
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Exploring-the-Investigative-World-of-Science.pdf/8th class curiosity/1st chap...
Sandeep Swamy
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
Module 1: Determinants of Health [Tutorial Slides]
JonathanHallett4
 
VOMITINGS - NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
INTESTINAL OBSTRUCTION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
Virus sequence retrieval from NCBI database
yamunaK13
 
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
Joint Mobility : Fundamentals of Joint Mobility
Sreeraj S R
 
GENERAL METHODS OF ISOLATION AND PURIFICATION OF MARINE__MPHARM.pptx
SHAHEEN SHABBIR
 
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
FULL DOCUMENT: Read the full Deloitte and Touche audit report on the National...
Kweku Zurek
 
Constitutional Design Civics Class 9.pptx
bikesh692
 

Ry pyconjp2015 turtle

  • 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. Python Turtle Graphics in Traditional Chinese (Kanji) 傳統漢字の Python 龜作圖 2
  • 3. 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 3 The term “Traditional Chinese” in this presentation may sometimes be used interchangeably with “Kanji”.
  • 4. 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 4http://github.com/renyuanL/pythonTurtleInChinese
  • 6. 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/] 6
  • 7. 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) 7 The first impression of this kind of program: SHORTER in length, more compact, and more readable, if you understand kanji (漢字).
  • 8. Ignition: UTF-8 used as Source encoding of Python 3.0 • 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 8
  • 9. An exception for translation: Python Keywords are NOT translated 9 >>> 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, used for grammatical purposes. – The number of them is about 30, quite few! • This small set of words cannot be used as identifiers, with the other considerations not mentioned here, they are left as the original forms without translation.
  • 10. A short example of Python in Kanji (漢字) 10 >>> 印= 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 >>>
  • 11. A longer example • An example to find prime numbers within 100. • It can be read aloud, like a normal Chinese article. 11 ''' 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] >>>
  • 12. Python Module for Turtle Graphics • Turtle graphics is a term in computer graphics • for a method of programming vector graphics using a relative cursor (the "turtle") upon a Cartesian plane. – [http://en.wikipedia.org/wiki/Turtle_graphics] • It was part of the original Logo programming language • developed by Wally Feurzig and Seymour Papert in 1966. – According to this, I find I am still younger than the Turtle  • The turtle module is an extended reimplementation • of the same-named module from the Python standard distribution up to version Python 2.5. 12
  • 13. 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. 13
  • 14. A typical example • An example from the set of turtle demo programs: yinyang.py 14 陰 陽
  • 15. 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() 主迴圈() 15 • 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.
  • 16. Readability counts • Anybody remember this Python’s Zen (禪)? 16 >>> 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. ... ... >>>
  • 17. 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! 17
  • 18. Translation of the whole set of 18 Turtle Demo programs 18
  • 19. 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 19
  • 21. Inside the turtle module (turtle.py) • The class diagram of the turtle module 21 class _Screen class Turtle
  • 22. 22 An analogy to the Scratch language (originated from MIT) Python Turtle Scratch class Turtle Sprite (貓精靈) class _Screen Stage (舞台)
  • 23. • A simplified class diagram 23
  • 24. 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 24 Diving into turtle.py improve my Python skills significantly!!
  • 25. 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 25 DownLoad @ http://github.com/renyuanL/pythonTurtleInChinese
  • 26. 26 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
  • 27. 27 >>> 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
  • 28. 28 >>> 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
  • 29. Let’s jump into turtle_tc.py for more detail 29
  • 30. Alias identifiers 龜幕基類= TurtleScreenBase 烏龜螢幕地基類= TurtleScreenBase 龜幕類= TurtleScreen 烏龜螢幕類= TurtleScreen 龜行類= TNavigator 烏龜航行類= TNavigator 龜筆類= TPen 烏龜畫筆類= TPen 原龜類= RawTurtle 粗龜類= RawTurtle 原生龜類= RawTurtle _幕類= _Screen _螢幕類= _Screen 幕類= Screen 螢幕類= Screen 開幕= Screen 龜類= Turtle 烏龜類= Turtle 30 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
  • 31. def x座標(): ... def y座標(): ... def 下筆(): ... def 下筆嗎(): ... def 下筆狀態(): ... def 位置(): ... def 傾斜(): ... def 傾斜角度(): ... def 前往(): ... def 前進(): ... def 半徑數(): ... def 去到(): ... def 點(): ... def 龜大小(): ... 31 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
  • 33. 33 Aliasing in method level (within class) (Hacking the source code??)
  • 34. 34 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.
  • 35. 35 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
  • 36. An extra important issue: Providing on-line help • A document file should also be provided to on-line help available. 36 >>> 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)
  • 37. Demo • On Youtube: – http://youtu.be/sQFKjlxw2mw • On NBViewer – http://nbviewer.ipython.org/urls/dl.dropbox.com/ s/4n70b5e82cy74n4/tesing_turtle_tc.ipynb# 37
  • 38. 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. 38 Thinking in English? or in native language ! How many of you can memorize and read out aloud the multiplication table in English, if your educational language in school is not English?
  • 39. Reference • [1] The whole set of 18 turtle demo programs – https://github.com/renyuanL/pythonTurtleInChinese/tree/mast er/tcExamples – Demo on youtube • http://youtu.be/sQFKjlxw2mw • [2] renyuanL/pythonTurtleInChinese – https://github.com/renyuanL/pythonTurtleInChinese • [3] ChinesePython – http://www.chinesepython.org/ • [4] Zhpy – https://code.google.com/p/zhpy/ • [5] Computer Programming for Everybody – https://www.python.org/doc/essays/cp4e/ • [6] PEP 3131 - Supporting Non-ASCII Identifiers – https://www.python.org/dev/peps/pep-3131/ 39
  • 40. 40 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/