472,969 Members | 1,988 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,969 software developers and data experts.

Changing the names of python keywords and functions

Hello,

I am trying to make a program for 3D modelling with "programming".And
I want make my own program commands,

for example when user type code in my program:

"<<koristiti>OS"- (THIS IS MY IMAGINARY EXAMPLE OF KEYWORD),

my program must write this code in some user file, but my

program must read this command like: "import os".How

can I do something like that??

Please, HELP ME somebody!!!

Jun 21 '07 #1
6 1296
I'm not quite clear on what you are asking, but
you can use the __import__() function to import modules by name.

On Jun 21, 3:07 pm, vedrandeko...@v-programs.com wrote:
Hello,

I am trying to make a program for 3D modelling with "programming".And
I want make my own program commands,

for example when user type code in my program:

"<<koristiti>OS"- (THIS IS MY IMAGINARY EXAMPLE OF KEYWORD),

my program must write this code in some user file, but my

program must read this command like: "import os".How

can I do something like that??

Please, HELP ME somebody!!!

Jun 21 '07 #2

moegoldb...@gmail.com je napisao/la:
I'm not quite clear on what you are asking, but
you can use the __import__() function to import modules by name.

I want to invent something like my "programming language" like Python
with the same keywords just changed,
for example if user type in my "programming language":
>>koristiti os
This line of code my program must write in some file, and my program
(when it run this user file) must read this
line of code like:
>>import os (I just want to change names of keywords)
Jun 21 '07 #3
"<<koristiti>OS"- (THIS IS MY IMAGINARY EXAMPLE OF KEYWORD),

my program must write this code in some user file, but my

program must read this command like: "import os".How

can I do something like that??
The keywords are listed in Grammar/Grammar. You need to edit
this file, then recompile.

Regards,
Martin
Jun 21 '07 #4
"Martin v. Löwis" <ma****@v.loewis.dewrites:
(unattributed author) wrote:
"<<koristiti>OS"- (THIS IS MY IMAGINARY EXAMPLE OF KEYWORD),
my program must write this code in some user file, but my
program must read this command like: "import os".How
can I do something like that??

The keywords are listed in Grammar/Grammar. You need to edit
this file, then recompile.
To clarify, are you suggesting changing the source code of the Python
implementation and recompiling it?

If the keywords are changed in the Python executable, won't that break
the import of any Python module written for the standard keywords --
such as many of those in the standard library?

My understanding of the original poster's requirement was that the
keywords should be additional to, not replacement for, the existing
Python keywords.

--
\ "The way to build large Python applications is to componentize |
`\ and loosely-couple the hell out of everything." -- Aahz |
_o__) |
Ben Finney
Jun 22 '07 #5
>>"<<koristiti>OS"- (THIS IS MY IMAGINARY EXAMPLE OF KEYWORD),
>>my program must write this code in some user file, but my
program must read this command like: "import os".How
can I do something like that??
The keywords are listed in Grammar/Grammar. You need to edit
this file, then recompile.

To clarify, are you suggesting changing the source code of the Python
implementation and recompiling it?
Correct.
If the keywords are changed in the Python executable, won't that break
the import of any Python module written for the standard keywords --
such as many of those in the standard library?
Most certainly, yes.
My understanding of the original poster's requirement was that the
keywords should be additional to, not replacement for, the existing
Python keywords.
So he should make them additional in the grammar, too.

It is entirely beyond me *why* the OP wants to do that, but changing
the compiler would be the proper way of implementing that change.

Regards,
Martin
Jun 22 '07 #6
ve***********@v-programs.com schrieb:
Hello,

I am trying to make a program for 3D modelling with "programming".And
I want make my own program commands,

for example when user type code in my program:

"<<koristiti>OS"- (THIS IS MY IMAGINARY EXAMPLE OF KEYWORD),

my program must write this code in some user file, but my

program must read this command like: "import os".How

can I do something like that??

Please, HELP ME somebody!!!
Besides your request is sorta weird (languages are mostly meant to give
a ruleset of expressions, not a framework of mutability, at least the
more widespread ones), Python does not support something like this out
of the box. There have been several discussions about such features and
they were all abandoned due to unification.

You can, of course, follow the "normal" track to implement any language
and write a parser, lexer, compiler and whatever. Tools like
`pyparsing`_ or `PLY`_ might help you (there are much more).
Though, there *is* a mutable codeset of Python called `Logix`_. As far
as I glanced at it, it is pretty mutable and might fit your needs perfectly.

Ah, and if you perhaps remove the leading << there, this might be pretty
much implementable by overloading __rshift__ at your koristiti object.

HTH,
Stargaming

... _pyparsing: http://pyparsing.wikispaces.com/
... _PLY: http://www.dabeaz.com/ply/ply.html
... _Logix: http://livelogix.net/logix/
Jun 22 '07 #7

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

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
49
by: Ville Vainio | last post by:
I don't know if you have seen this before, but here goes: http://text.userlinux.com/white_paper.html There is a jab at Python, though, mentioning that Ruby is more "refined". -- Ville...
12
by: Ryan Paul | last post by:
I've spent a lot of time using python, and personally, I feel like it is vastly superior when compared to languages like java, and c++, but there are still a few things that detract from its...
0
by: Veli-Pekka Tštilš | last post by:
Hi, My first post here. I've found some serious accessibility flaws in the Python 2.4 docs and wish they could be rectified over time. I'm very new to Python and initially contacted docs at python...
0
by: todddeluca | last post by:
I am posting code for calling almost any python function from php, because it seems generally useful. Please feel free to suggest improvements or tell me this has already been done better...
7
by: Petr Jakes | last post by:
I have got names of functions stored in the file. For the simplicity expect one row only with two function names: printFoo, printFOO In my code I would like to define functions and then to read...
16
by: per9000 | last post by:
Hi, I recently started working a lot more in python than I have done in the past. And I discovered something that totally removed the pretty pink clouds of beautifulness that had surrounded my...
6
by: vedrandekovic | last post by:
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!!!!!! ...
7
by: Maximus Decimus | last post by:
HI all, I am using python v2.5 and I am an amateur working on python. I am extending python for my research work and would like some help and guidance w.r.t this matter from you experienced...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
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
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
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...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
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
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...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.