472,954 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,954 software developers and data experts.

Python changing keywords name

Hello AGAIN,

I on working on windows and Python 2.4. Where can I find and CHANGE
python
grammar. ( I just want to change the keywords )

PLEASE HELP ME
SOMEBODY!!!!!!

THANKS!!!!!!!!!!!!!!!!!

Jun 23 '07 #1
6 2441
ve***********@v-programs.com wrote:
Hello AGAIN,

I on working on windows and Python 2.4. Where can I find and CHANGE
python
grammar. ( I just want to change the keywords )

PLEASE HELP ME
SOMEBODY!!!!!!

THANKS!!!!!!!!!!!!!!!!!
This is the third time you have posted this today. Please stop.

Also, you might want to moderate the tone of your messages. Some people
might find a string of all caps and exclamation marks obnoxious. I think
it is less likely to get you help.

You may find this guide helpful
<http://www.catb.org/~esr/faqs/smart-questions.html>.
--
Michael Hoffman
Jun 23 '07 #2
ve***********@v-programs.com wrote:
Hello AGAIN,

I on working on windows and Python 2.4. Where can I find and CHANGE
python
grammar. ( I just want to change the keywords )

PLEASE HELP ME
SOMEBODY!!!!!!

THANKS!!!!!!!!!!!!!!!!!
1. Download the source to python
2. Unpack the source
3. Change to the "Grammar" directory
5. Edit the "Grammar" file appropriately
6. Compile python
7. Your interpreter now has new keywords
8. Use at your own risk.

For example, I changed a print statent in this file from

print_stmt: 'print' ( [ test (',' test)* [','] ] |
'>>' test [ (',' test)+ [','] ] )

to

print_stmt: 'splodnik' ( [ test (',' test)* [','] ] |
'>>' test [ (',' test)+ [','] ] )

And here are the results:

Python 2.5 (r25:51908, Jun 23 2007, 14:42:05)
[GCC 4.1.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>splodnik 'This is a splodnik statement.'
This is a splodnik statement.

You will also want to change every instance of the word "print" in every
..py file to "splodnik" in the pythonsource before building, so that you
won't break your standard lib. Also, no one else on the planet will be
using this version of python, so you will not be able to use any one
else's python code unless you replace keywords in their python source.

Now that you know how to do this, please don't ask again.

James
Jun 23 '07 #3
vedrandeko...@v-programs.com wrote:
I on working on windows and Python 2.4. Where can I find and CHANGE
python
grammar. ( I just want to change the keywords )
Instead of changing Python grammar, you could convert your
"translated" source into "original" Python using the code below, and
compile and run as usual; you can also reverse the process. Also, this
lets you use the standard Python library and all other Python code
around the world.
Unlike a simple "search and replace", it understands the lexical
structure of a Python program, and won't replace a keyword inside a
quoted string, by example.
The core function is simple:

def translate_tokens(sourcefile, tdict):
for tok_num, tok_val, _, _, _ in
tokenize.generate_tokens(sourcefile.readline):
if tok_num==token.NAME: tok_val = tdict.get(tok_val, tok_val)
yield tok_num, tok_val

translated_code = tokenize.untokenize(
translate_tokens(StringIO(original_code), translation_dictionary))

Note that you may encounter problems if the original code uses some
names matching the translated keywords.

(I hope nobody will abuse this technique... Y perdón a los
hispanoparlantes por lo horrible de la traducción).

--- begin code ---
from cStringIO import StringIO
import token
import tokenize

# "spanished" Python source from the SimplePrograms wiki page
code_es = r"""
BOARD_SIZE = 8

clase BailOut(Exception):
pasar

def validate(queens):
left = right = col = queens[-1]
para r en reversed(queens[:-1]):
left, right = left-1, right+1
si r en (left, col, right):
lanzar BailOut

def add_queen(queens):
para i en range(BOARD_SIZE):
test_queens = queens + [i]
intentar:
validate(test_queens)
si len(test_queens) == BOARD_SIZE:
retornar test_queens
else:
retornar add_queen(test_queens)
excepto BailOut:
pasar
lanzar BailOut

queens = add_queen([])
imprimir queens
imprimir "\n".join(". "*q + "Q " + ". "*(BOARD_SIZE-q-1) para q en
queens)
"""

# english keyword -spanish
trans_en2es = {
'and': 'y',
'as': 'como',
'assert': 'afirmar',
'break': 'afuera',
'class': 'clase',
'continue': 'siguiente',
'def': 'def',
'del': 'elim',
'elif': 'sinosi',
'else': 'sino',
'except': 'excepto',
'exec': 'ejecutar',
'finally': 'finalmente',
'for': 'para',
'from': 'desde',
'global': 'global',
'if': 'si',
'import': 'importar',
'in': 'en',
'is': 'es',
'lambda': 'lambda',
'not': 'no',
'or': 'o',
'pass': 'pasar',
'print': 'imprimir',
'raise': 'lanzar',
'return': 'retornar',
'try': 'intentar',
'while': 'mientras',
'with': 'con',
'yield': 'producir',
}
# reverse dict
trans_es2en = dict((v,k) for (k,v) in trans_en2es.items())

def translate_tokens(source, tdict):
for tok_num, tok_val, _, _, _ in
tokenize.generate_tokens(source.readline):
if tok_num==token.NAME: tok_val = tdict.get(tok_val, tok_val)
yield tok_num, tok_val

code_en = tokenize.untokenize(translate_tokens(StringIO(code _es),
trans_es2en))
print code_en
code_es2= tokenize.untokenize(translate_tokens(StringIO(code _en),
trans_en2es))
print code_es2
--- end code ---

--
Gabriel Genellina

PS: Asking just once is enough.

Jun 24 '07 #4
Gabriel Genellina <ga*******@yahoo.com.arwrote:
>(I hope nobody will abuse this technique... Y perd=F3n a los
hispanoparlantes por lo horrible de la traducci=F3n).
Ah, I only spotted this when I came to post a response. And the
reason I was going to post a response was that these:
'assert': 'afirmar',
'exec': 'ejecutar',
'import': 'importar',
'pass': 'pasar',
'print': 'imprimir',
'raise': 'lanzar',
'return': 'retornar',
'try': 'intentar',
'yield': 'producir',
look rather odd to this non-native Spanish speaker (or at least
reader), and I was going to ask if they sounded more idiomatically
correct if it's not your nth language. I guess they don't 8-)

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
"Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
Jun 26 '07 #5
En Tue, 26 Jun 2007 13:11:50 -0300, Sion Arrowsmith
<si***@chiark.greenend.org.ukescribió:
Gabriel Genellina <ga*******@yahoo.com.arwrote:
>(I hope nobody will abuse this technique... Y perd=F3n a los
hispanoparlantes por lo horrible de la traducci=F3n).

Ah, I only spotted this when I came to post a response. And the
reason I was going to post a response was that these:
> 'assert': 'afirmar',
'exec': 'ejecutar',
'import': 'importar',
'pass': 'pasar',
'print': 'imprimir',
'raise': 'lanzar',
'return': 'retornar',
'try': 'intentar',
'yield': 'producir',

look rather odd to this non-native Spanish speaker (or at least
reader), and I was going to ask if they sounded more idiomatically
correct if it's not your nth language. I guess they don't 8-)
They are... ugly, yes. If I were to choose the names in Spanish, I'd use
other words unrelated to the Python original keywords. For example, "pass"
would become "nada" ("nothing") (why was chosen "pass" in the first
place?) and "continue" would be "siguiente" ("next") and "break" would be
"salir" ("go out","quit"). "except" is hard to translate, and even in
English I don't see what is the intended meaning (is it a noun? a verb? an
adverb? all look wrong). The pair "throw/catch" would be easier to use.
And "with" would be "usando" ("using").
BTW, usage of "print" instead of "display" or "show" became obsolete 30
years ago or so...
For a "real" Python translation, new versions with new keywords are a
problem - what if "using" is added to the language and it conflicts with
the translation of "with"?
So... let's stay with the original keywords (english or dutglish or
whatever they are...)

--
Gabriel Genellina
Jun 27 '07 #6
Gabriel Genellina wrote:
"except" is hard to translate, and
even in English I don't see what is the intended meaning (is it a noun?
a verb? an adverb? all look wrong).
It's a preposition.
--
Michael Hoffman
Jul 2 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Robert-Paul | last post by:
Hi there. I have a problem after changing the assembly name of a class library. I have two projects in one solution: - a Windows application (.exe) - Class Library. There is a references...
4
by: Ant | last post by:
Hi, I'm a Vb6 developer just getting into .Net & I like it! But... How do I change the name of a control, say, a button, once code has been written to it. Even if I delete the old event,...
2
by: Aaron Queenan | last post by:
Is there any way to change the name of a tab at runtime (after the dialogue has been displayed)? Alternately, is there any way to add and remove tab without causing the screen to flicker? ...
1
by: nsyforce | last post by:
Can you change the domain name in an HTTPModule? I have seen examples of changing the relative url in an HTTP Module, such as the following: protected void AuthenticateRequest(object sender,...
1
by: William H. Burling | last post by:
i have a nest of vb.vanilla collections. CollectionofHotelData.item("great Pequot").item("2000").item(22) The above works. I wrote the code that constructs the nested collections and i can...
3
by: Bonzol | last post by:
Vb.net 2003, Web application Hey all! Just a quick question. I have a site which allows users the ability to upload files by the HTML brows button control. My question is if a user submits...
0
by: BrianT | last post by:
I'm trying to build code that allows the computer name to be changed, then asks the user to reboot to make the change affective. I got the code working when logged in as the local computer...
11
by: =?Utf-8?B?UGF1bA==?= | last post by:
I did a google search but could find what I was looking for. I am creating a temporary folder and placing files in it with a web application. The temporary folder name needs to be changed...
4
by: Harry | last post by:
Hi there. I am trying to download a file(sn.last) from a public FTP server with the following code: from ftplib import FTP ftp=FTP('tgftp.nws.noaa.gov') ftp.login()...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.