SlideShare uma empresa Scribd logo
1 de 40
Baixar para ler offline
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/

Mais conteúdo relacionado

Mais procurados

Pydiomatic
PydiomaticPydiomatic
Pydiomaticrik0
 
Python programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - KalamasseryPython programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - KalamasserySHAMJITH KM
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Pedro Rodrigues
 
Introduction to advanced python
Introduction to advanced pythonIntroduction to advanced python
Introduction to advanced pythonCharles-Axel Dein
 
Learn Python The Hard Way Presentation
Learn Python The Hard Way PresentationLearn Python The Hard Way Presentation
Learn Python The Hard Way PresentationAmira ElSharkawy
 
Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Jaganadh Gopinadhan
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Edureka!
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programmingDamian T. Gordon
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Pedro Rodrigues
 

Mais procurados (20)

Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python basic
Python basicPython basic
Python basic
 
Python programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - KalamasseryPython programming Workshop SITTTR - Kalamassery
Python programming Workshop SITTTR - Kalamassery
 
Python ppt
Python pptPython ppt
Python ppt
 
Python Basics
Python Basics Python Basics
Python Basics
 
Erlang
ErlangErlang
Erlang
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Go Java, Go!
Go Java, Go!Go Java, Go!
Go Java, Go!
 
Introduction to advanced python
Introduction to advanced pythonIntroduction to advanced python
Introduction to advanced python
 
Go Java, Go!
Go Java, Go!Go Java, Go!
Go Java, Go!
 
Python basics
Python basicsPython basics
Python basics
 
Python
PythonPython
Python
 
Learn Python The Hard Way Presentation
Learn Python The Hard Way PresentationLearn Python The Hard Way Presentation
Learn Python The Hard Way Presentation
 
Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programming
 
Python numbers
Python numbersPython numbers
Python numbers
 
Python basics
Python basicsPython basics
Python basics
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)
 

Semelhante a Ry pyconjp2015 turtle

pyconjp2015_talk_Translation of Python Program__
pyconjp2015_talk_Translation of Python Program__pyconjp2015_talk_Translation of Python Program__
pyconjp2015_talk_Translation of Python Program__Renyuan Lyu
 
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.pptxsangeeta borde
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayUtkarsh Sengar
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxNimrahafzal1
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1Abdul Haseeb
 
python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slidejonycse
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxCatherineVania1
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methodsPranavSB
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 

Semelhante a Ry pyconjp2015 turtle (20)

pyconjp2015_talk_Translation of Python Program__
pyconjp2015_talk_Translation of Python Program__pyconjp2015_talk_Translation of Python Program__
pyconjp2015_talk_Translation of Python Program__
 
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
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Lec-1c.pdf
Lec-1c.pdfLec-1c.pdf
Lec-1c.pdf
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1
 
python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slide
 
Python overview
Python   overviewPython   overview
Python overview
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptx
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methods
 
Python basics
Python basicsPython basics
Python basics
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 

Mais de Renyuan Lyu

Py conjp2019 renyuanlyu_3
Py conjp2019 renyuanlyu_3Py conjp2019 renyuanlyu_3
Py conjp2019 renyuanlyu_3Renyuan Lyu
 
Py conjp2019 renyuanlyu_3
Py conjp2019 renyuanlyu_3Py conjp2019 renyuanlyu_3
Py conjp2019 renyuanlyu_3Renyuan Lyu
 
Py conjp2019 renyuanlyu_3
Py conjp2019 renyuanlyu_3Py conjp2019 renyuanlyu_3
Py conjp2019 renyuanlyu_3Renyuan Lyu
 
Lightning talk01 docx
Lightning talk01 docxLightning talk01 docx
Lightning talk01 docxRenyuan Lyu
 
Lightning talk01
Lightning talk01Lightning talk01
Lightning talk01Renyuan Lyu
 
Pycon JP 2016 ---- Pitch Detection
Pycon JP 2016 ---- Pitch DetectionPycon JP 2016 ---- Pitch Detection
Pycon JP 2016 ---- Pitch DetectionRenyuan Lyu
 
pycon jp 2016 ---- CguTranslate
pycon jp 2016 ---- CguTranslatepycon jp 2016 ---- CguTranslate
pycon jp 2016 ---- CguTranslateRenyuan Lyu
 
Ry pyconjp2015 karaoke
Ry pyconjp2015 karaokeRy pyconjp2015 karaoke
Ry pyconjp2015 karaokeRenyuan Lyu
 
教青少年寫程式
教青少年寫程式教青少年寫程式
教青少年寫程式Renyuan Lyu
 

Mais de Renyuan Lyu (10)

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
 
Ry pyconjp2015 karaoke
Ry pyconjp2015 karaokeRy pyconjp2015 karaoke
Ry pyconjp2015 karaoke
 
教青少年寫程式
教青少年寫程式教青少年寫程式
教青少年寫程式
 
Pycon apac 2014
Pycon apac 2014Pycon apac 2014
Pycon apac 2014
 

Último

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
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 GraphThiyagu K
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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 ModeThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 

Último (20)

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
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
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 

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/