473,395 Members | 2,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 3143
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: optimistx | last post by:
How to build or find an object browser for javascript? E.g. Delphi integrated developement environment ('ide') offers a very practical object browser for Pascal language. When typing a name with...
6
by: Josef Angermeier | last post by:
Hello I need to write lots of wrapper functions, which look like that: wrapper_my_func(int a, int b) { my_func(a, b); <extra_code>
0
by: David Duerrenmatt | last post by:
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,...
5
by: reycri | last post by:
Hi, I need to be able to do this: var func = new Function("var me = <selfRef>; alert(me.params);"); func.params = "This is a test parameter"; window.setTimeout(func, 500); Basically, I...
24
by: dmitrey | last post by:
Hi all, I looked to the PEPs & didn't find a proposition to remove brackets & commas for to make Python func call syntax caml- or tcl- like: instead of result = myfun(param1, myfun2(param5,...
3
by: tguclu | last post by:
Hi there, I hope this is the right place for my question if not please accept my apologies. In my application I want to mount/umount file system. From GNU C Library Reference Manual, for...
2
by: FFMG | last post by:
Hi, I was looking at http://www.php.net/manual/en/function.call-user-func-array.php and I was wondering... Given, // -- function foo( &$params) {
13
by: Tim H | last post by:
Goal: to provide the simplest call-site possible at the cost of upfront hackery. I have a function that essentially takes a variable list of arguments: func(const string &k0, unsigned long...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.