473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 2460
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.