Wrap a function
Jonathan Gardner
jgardner at jonathangardner.net
Thu Jan 28 16:40:20 EST 2010
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")
More information about the Python-list
mailing list