Wrap a function

Joan Miller peloko45 at gmail.com
Thu Jan 28 23:16:52 CET 2010


On 28 ene, 21:40, Jonathan Gardner <jgard... at jonathangardner.net>
wrote:
> On Jan 28, 10:20 am, Joan Miller <pelok... at gmail.com> wrote:
>
>
>
> > I've to call to many functions with the format:
>
> > >>> run("cmd")
>
> > were "cmd" is a command with its arguments to pass them to the shell
> > and run it, i.e.
>
> > >>>  run("pwd")
> > or
> > >>> run("ls /home")
>
> > Does anybody knows any library to help me to avoid the use of the main
> > quotes, and brackets?
>
> > I would to use anything as:
>
> > $ ls /home => run("ls /home")
>
> > or, at least
>
> > run pwd => run("pwd")
>
> How about this?
>
> def pwd(): return run("pwd")
>
> pwd()
>
> def ls(l=False, files=()):
>     args = []
>     if l: args.insert(0, '-l')
>     args.append(files)
>     return run("ls", args)
>
> ls(l=True, "/foo")

There would be to make a function for each system command to use so it
would be too inefficient, and follow the problem with the quotes.

The best is make a parser into a compiled language



More information about the Python-list mailing list