Extending Python questions

Diez B. Roggisch deetsNOSPAM at web.de
Wed Nov 3 12:46:49 EST 2004


> myshell.openconnection('www.yahoo.com',12,2000)
> 
> It's not only the problem of comfort - it's a problem of changing
> *some* scripts. And there's more than that - my shell functions
> already know how to handle it's arguments (which's number may vary),
> it doesn't need python to do that. All it needs is a pointer to a
> string representing the arguments (in our case "www.yahoo.com 12
> 2000"). I've tried using PyArg_UnpackTuple but without success.

Then don't specify the arguments separately, but instead make it one string
argument, and pass it to your command:

myshell.openconnection('www.yahoo.com 12 2000')


> So I have two questions:
> 1. Is it possible to move the calls to a upper level (i.e. call
> "openconnection" and  not "myshell.openconnection") ?

from myshell import *

> 2. Is is possible to remove the brackets and commas? (i.e.
> "www.yahoo.com 12 2000" instead of ('www.yahoo.com',12,2000)?

No. Thats too much of tinkering with pythons parser - you'd render all other
python sources useless, which I suspect outnumber your scripts by a degree
or two... :)
 
> final goal is to use the original commands if possible.
> thanks in advance,

What do you use python for in the first place, if you want to keep
everything as it is?

What you can do is to read your scripts _using_ python instead of _passing_
them to python - then you can control the syntax of your scripting
language. The main loop could look like this:

import myshell
for line in sys.stdin.readlines():
    command, rest = line.split()[0], " ".join(line.split()[1:])
    getattr(myshell, command)(rest)


-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list