Using non-ascii symbols
Runsun Pan
python.pan at gmail.com
Thu Jan 26 12:23:33 EST 2006
On 1/26/06, Terry Hancock <hancock at anansispaceworks.com> wrote:
> On Thu, 26 Jan 2006 01:12:10 -0600
> Runsun Pan <python.pan at gmail.com> wrote:
> > Error) in python. I'd love to see if I can use han char
> > for all those keywords like import, but it doesn't work.
>
> Yeah, I'm pretty sure we're talking about the future here.
How do you like this (see below) as a python program ?
:) :)
#---------------------------------------------- han python
輸入 操作系統
顯示 操作系統.path.realpath( 操作系統.目前目錄 )
a 等於 3 加 15
顯示 a
對於 i 在 (範圍(5)): 顯示 '(%s)'%(i 加 4)
#---------------------------------------------- end
The following file does work:
########################## test_hanzi.py BEGIN
charmap={
'顯示' : 'print',
'輸入' : 'import',
'加' : '+',
'在' : 'in',
'等於' : '=',
'目前目錄': 'curdir',
'操作系統': 'os',
'對於' : 'for',
'範圍' : 'range',
}
file = 'c:/t/test_hanzi_script.py'
def convert(raw, charmap=charmap):
for k,v in charmap.items():
raw = raw.replace( k,v)
return raw
def exehan(raw):
doc = convert(raw)
print '-'*20,'\n','Converted doc:'
print doc
print '-'*20
open(file, 'w').write( doc )
s = os.popen('python '+ file, 'r').read()
print 'Output of the raw:\n'
print s
return s
#----------------------------------------------
raw='''
輸入 操作系統
顯示 操作系統.path.realpath( 操作系統.目前目錄 )
a 等於 3 加 15
顯示 a
對於 i 在 (範圍(5)): 顯示 '(%s)'%(i 加 4)
'''
exehan(raw)
########################## test_hanzi.py END
Certainly, this kind of approach is not very practical.
--
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Runsun Pan, PhD
python.pan at gmail.com
Nat'l Center for Macromolecular Imaging
http://ncmi.bcm.tmc.edu/ncmi/
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
More information about the Python-list
mailing list