469,289 Members | 2,330 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,289 developers. It's quick & easy.

func(*params)

Hi there

For some reasons, I've to use Python 1.5.2 and am looking for a workaround:

In newer Python versions, I can call a function this way:

func = some_function
func(*params)

Then, the list/tuple named params will automatically be "expanded" and
n=len(params) arguments will be submitted.

Python 1.5.2 doesn't support this kind of function call. I could use
some workaround like:

func(params[0],params[1]...)

but since the number of items in params varies and depends on the mapped
function "some_function", this isn't a good solution.

Another idea is to use exec(), don't know whether this is safe...

Any recommondations or tricks?
Thanks,
david
Nov 22 '05 #1
8 2905
David Duerrenmatt wrote:
For some reasons, I've to use Python 1.5.2 and am looking for a
workaround:

In newer Python versions, I can call a function this way:

func = some_function
func(*params)


Use

apply(func, params)

Peter

Nov 22 '05 #2
David Duerrenmatt wrote:
For some reasons, I've to use Python 1.5.2 and am looking for a
workaround:

In newer Python versions, I can call a function this way:

func = some_function
func(*params)


Use

apply(func, params)

Peter

Nov 22 '05 #3
David Duerrenmatt wrote:
Hi there

For some reasons, I've to use Python 1.5.2 and am looking for a workaround:

In newer Python versions, I can call a function this way:

func = some_function
func(*params)


I think the "apply" function is what you want:

apply(object[, args[, kwargs]]) -> value

Call a callable object with positional arguments taken from the tuple
args, and keyword arguments taken from the optional dictionary kwargs.
Note that classes are callable, as are instances with a __call__()
method.

Deprecated since release 2.3. Instead, use the extended call syntax:
function(*args, **keywords).

Nov 22 '05 #4
David Duerrenmatt wrote:
Hi there

For some reasons, I've to use Python 1.5.2 and am looking for a workaround:

In newer Python versions, I can call a function this way:

func = some_function
func(*params)


I think the "apply" function is what you want:

apply(object[, args[, kwargs]]) -> value

Call a callable object with positional arguments taken from the tuple
args, and keyword arguments taken from the optional dictionary kwargs.
Note that classes are callable, as are instances with a __call__()
method.

Deprecated since release 2.3. Instead, use the extended call syntax:
function(*args, **keywords).

Nov 22 '05 #5
Great, this is exactly what I was looking for.

Thanks all of you for your immediate answer!


Nick Smallbone schrieb:
David Duerrenmatt wrote:
Hi there

For some reasons, I've to use Python 1.5.2 and am looking for a workaround:

In newer Python versions, I can call a function this way:

func = some_function
func(*params)

I think the "apply" function is what you want:

apply(object[, args[, kwargs]]) -> value

Call a callable object with positional arguments taken from the tuple
args, and keyword arguments taken from the optional dictionary kwargs.
Note that classes are callable, as are instances with a __call__()
method.

Deprecated since release 2.3. Instead, use the extended call syntax:
function(*args, **keywords).

Nov 22 '05 #6
Great, this is exactly what I was looking for.

Thanks all of you for your immediate answer!


Nick Smallbone schrieb:
David Duerrenmatt wrote:
Hi there

For some reasons, I've to use Python 1.5.2 and am looking for a workaround:

In newer Python versions, I can call a function this way:

func = some_function
func(*params)

I think the "apply" function is what you want:

apply(object[, args[, kwargs]]) -> value

Call a callable object with positional arguments taken from the tuple
args, and keyword arguments taken from the optional dictionary kwargs.
Note that classes are callable, as are instances with a __call__()
method.

Deprecated since release 2.3. Instead, use the extended call syntax:
function(*args, **keywords).

Nov 22 '05 #7
David Duerrenmatt wrote:
For some reasons, I've to use Python 1.5.2 and am looking for a workaround:

In newer Python versions, I can call a function this way:

func = some_function
func(*params)

Then, the list/tuple named params will automatically be "expanded" and
n=len(params) arguments will be submitted.

Python 1.5.2 doesn't support this kind of function call.


use

apply(func, params)

or

result = apply(func, params)

more info:
help(apply)

Help on built-in function apply in module __builtin__:

apply(...)
apply(object[, args[, kwargs]]) -> value

Call a callable object with positional arguments taken from the tuple args,
and keyword arguments taken from the optional dictionary kwargs.
Note that classes are callable, as are instances with a __call__() method.

Deprecated since release 2.3. Instead, use the extended call syntax:
function(*args, **keywords).

</F>

Nov 22 '05 #8
David Duerrenmatt wrote:
For some reasons, I've to use Python 1.5.2 and am looking for a workaround:

In newer Python versions, I can call a function this way:

func = some_function
func(*params)

Then, the list/tuple named params will automatically be "expanded" and
n=len(params) arguments will be submitted.

Python 1.5.2 doesn't support this kind of function call.


use

apply(func, params)

or

result = apply(func, params)

more info:
help(apply)

Help on built-in function apply in module __builtin__:

apply(...)
apply(object[, args[, kwargs]]) -> value

Call a callable object with positional arguments taken from the tuple args,
and keyword arguments taken from the optional dictionary kwargs.
Note that classes are callable, as are instances with a __call__() method.

Deprecated since release 2.3. Instead, use the extended call syntax:
function(*args, **keywords).

</F>

Nov 22 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by optimistx | last post: by
6 posts views Thread by Josef Angermeier | last post: by
reply views Thread by David Duerrenmatt | last post: by
3 posts views Thread by tguclu | last post: by
13 posts views Thread by Tim H | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.