471,350 Members | 1,605 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 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 1230
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

699 posts views Thread by mike420 | last post: by
12 posts views Thread by Ryan Paul | last post: by
reply views Thread by Veli-Pekka Tštilš | last post: by
reply views Thread by todddeluca | last post: by
7 posts views Thread by Petr Jakes | last post: by
16 posts views Thread by per9000 | last post: by
6 posts views Thread by vedrandekovic | last post: by
7 posts views Thread by Maximus Decimus | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.