From: <ge...@ce...> - 2007-04-15 18:27:34
|
Thanx a lot. Really helpful everybody As far as why: I would like to implement an execute-like commnad like "my_exec foo(bar)" and some unix-shell_like commands like cd.... >>On 4/14/07, ge...@ce... <ge...@ce...> wrote: >> 2. If I want to implement a keyword-like function like print or import how >do I >> do it? I want to have something like that : foo bar , and execute foo with >param >> bar. A function that doesn't require parenthesis. Could someone tell me >where I >> can find such implementation in the jython source code? >AFAIK you can not override or define your function this way (BTW why >do you need this in the first place?) and there is standard Python >module "shlex" that can be used for constructing your own >Unix_shell_like interpeters. >-- >Petr Gladkikh > Hi again, > > > > 2. If I want to implement a keyword-like function like print or import > how do I > > > do it? I want to have something like that : foo bar , and execute foo > with param > > > bar. A function that doesn't require parenthesis. Could someone tell me > where I > > > can find such implementation in the jython source code? > > Looking around for that kind of an implementation, I figured out that > you can write a python file by the name of 'foo.py' and make it accept > arguments. :) > > So that is POSSIBLE without a lot of HACKING. :) > > Hope that helps. > > --musically_ut > > > On 4/15/07, Utkarsh Upadhyay <mus...@gm...> wrote: > > Hi there, > > > > > 1. Surely it is answered already, but I don't find such an answer. I want > to > > > know which is more efficient, coding to python or java? I mean for > operations > > > that are present in jython through both python and jython. For > simplicity: > > > > > What is more efficient and what is the usual to follow, what is the > jythonic way? > > > > Well, this indeed is an oft asked question, asked so so often that > > there are separate tools for the process called 'profilers'. You can > > look them up on Google, or even the Python Manual. > > > > BTW, to answer your question, I used the module 'profile' and got the > > following results: > > > > > > > > In [0]: import math > > > In [1]: math.pow(2,2) > > > Out [1]: 4.0 > > > > >>> 2 function calls in 0.250 CPU seconds > > > > > In [2]: from java.lang import Math > > > In [3]: Math.pow(2,2) > > > Out [3]: 4.0 > > > > > > > >>> 2 function calls in 0.015 CPU seconds > > > > In the hind sight, the results seem somewhat obvious (though I never > > imagined such an order of magnitude of difference). The jython code is > > after all converted to a Java analogue and then run (NOT TO BE TAKEN > > LITERALLY, there is a LOT behind the process). So a direct Java > > implementation ought to make it somewhat straight forward for Jython, > > resulting in a faster code. > > > > > > > > 2. If I want to implement a keyword-like function like print or import > how do I > > > do it? I want to have something like that : foo bar , and execute foo > with param > > > bar. A function that doesn't require parenthesis. Could someone tell me > where I > > > can find such implementation in the jython source code? > > > > > > > This may not be all that wise, neither fruitful, an idea. It can be > > done with considerable hacking of the course code, but then there must > > exist a Pythonic way of doing the same thing. > > > > --musically_ut > > > > -- > > Never trust a spiritual leader who cannot dance. ~Mr. Miyagi, The Next > > Karate Kid > > > > > -- > Never trust a spiritual leader who cannot dance. ~Mr. Miyagi, The Next > Karate Kid > ---------------------------------------------------- This mail was sent through http://my.ceid.upatras.gr |