473,396 Members | 1,766 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,396 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 1314
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.