Renaming identifiers & debugging

MRAB python at mrabarnett.plus.com
Thu Feb 25 14:57:51 EST 2010


Luca wrote:
> Chris Rebert wrote:
>> On Thu, Feb 25, 2010 at 7:26 AM, Luca <lucat at despammed.com> wrote:
>>> Hello, i am trying to develop an application to teach programming to 
>>> young
>>> kids in a similar way as Logo did in the past. I would like to use an
>>> embedded Python as underlying language but this raises a problem.
>>>
>>> The target of my app are very young kids that might be unfamiliar with
>>> english, so i am wondering if there is a way to rename/redefine 
>>> identifiers
>>> and messages in the language of the kid.
>>>
>>> In UCB-Logo this is very easy with the command
>>>  COPYDEF "newidentifier "oldidentifier
>>> so all you have to do is setup a startup script to redefine all the
>>> identifiers to the language of the user.
>>>
>>> Is there anything similar for python? Since python would be embedded it
>>> would not be a problem for me to do it through some API.
>>
>> It can certainly be done (c.f. ChinesePython -
>> http://www.chinesepython.org/cgi_bin/cgb.cgi/english/english.html),
>> but I know of no framework that simplifies the task. Essentially, you
>> just have to manually modify Python's parser by swapping out the
>> english for the other language (and if you want to mess with the basic
>> types' names, their name definitions somewhere else too). There also
>> might be encoding issues to deal with.
>>
>> Cheers,
>> Chris
>> -- 
>> http://blog.rebertia.com
> 
> Yes, i am playing with Python source code, i have changed some keywords 
> but the compile-process fails when it tries to compile some of python 
> libraries which, of course, use english keywords... so i guess this is 
> not a very clean/viable solution (without having to rewrite several 
> parts of the libraries). A better solution could be to "duplicate" 
> keywords adding a translated version but leaving the original version in 
> place so that every module keeps working. In few words, if i was going 
> to translate the keyword "if" in, say, italian "se", then i would have 
> both "if" and also "se" working at the same time, in the same manner.
> I think that the best way to do this is to insert a "filter" somewhere 
> that converts every "se" keyword into a "if" keyword so that python 
> doesn't even see the change.
> 
> What i would like to do is add a new keyword (lets call it "copydef" 
> like in UCBLogo or whatever) that does this work at runtime by keeping a 
> substitution table in RAM. If i could manage to add this new keyword to 
> python then it would be easy to write a startup script that translates 
> the keywords once python is "up and running" and without breaking 
> existing python programs/libraries (unless the new keyword conflicts 
> with functions defined inside these programs/libraries).
> 
Perhaps you could use a different extension, eg ".pyn", so existing
".py" files are handled as-is but ".pyn" files are read through a
translator.



More information about the Python-list mailing list