Is there a Python profiler that preserves function arguments?

2020-03-11 Thread Go Luhng
I'm profiling a Python function `foo()` that takes a single argument, but that argument makes a huge difference in what the function actually does. Currently I'm using `cProfile`, which records every call to `foo()` as if it was the same, preventing me from figuring out what's going on. Is there

Re: Get Count of function arguments passed in

2019-09-11 Thread Roel Schroeven
Sayth Renshaw schreef op 11/09/2019 om 12:11: I want to allow as many lists as needed to be passed into a function. But how can I determine how many lists have been passed in? I expected this to return 3 but it only returned 1. matrix1 = [[1, -2], [-3, 4],] matrix2 = [[2, -1], [0, -1]] matrix3

Re: Get Count of function arguments passed in

2019-09-11 Thread David Lowry-Duda
> I expected this to return 3 but it only returned 1. > > matrix1 = [[1, -2], [-3, 4],] > matrix2 = [[2, -1], [0, -1]] > matrix3 = [[2, -1], [0, -1]] > > def add(*matrix): > print(len(locals())) > > print(add(matrix1, matrix2)) In this case, locals will be a dictionary with exactly one key.

Re: Get Count of function arguments passed in

2019-09-11 Thread ast
Le 11/09/2019 à 12:11, Sayth Renshaw a écrit : Hi I want to allow as many lists as needed to be passed into a function. But how can I determine how many lists have been passed in? I expected this to return 3 but it only returned 1. matrix1 = [[1, -2], [-3, 4],] matrix2 = [[2, -1], [0, -1]] mat

Re: Get Count of function arguments passed in

2019-09-11 Thread Sayth Renshaw
On Wednesday, 11 September 2019 20:25:32 UTC+10, Sayth Renshaw wrote: > On Wednesday, 11 September 2019 20:11:21 UTC+10, Sayth Renshaw wrote: > > Hi > > > > I want to allow as many lists as needed to be passed into a function. > > But how can I determine how many lists have been passed in? > >

Re: Get Count of function arguments passed in

2019-09-11 Thread Sayth Renshaw
On Wednesday, 11 September 2019 20:11:21 UTC+10, Sayth Renshaw wrote: > Hi > > I want to allow as many lists as needed to be passed into a function. > But how can I determine how many lists have been passed in? > > I expected this to return 3 but it only returned 1. > > matrix1 = [[1, -2], [-3,

Get Count of function arguments passed in

2019-09-11 Thread Sayth Renshaw
Hi I want to allow as many lists as needed to be passed into a function. But how can I determine how many lists have been passed in? I expected this to return 3 but it only returned 1. matrix1 = [[1, -2], [-3, 4],] matrix2 = [[2, -1], [0, -1]] matrix3 = [[2, -1], [0, -1]] # print(add(matrix1, ma

Re: Meaning of * in the function arguments list

2014-10-29 Thread Terry Reedy
On 10/29/2014 4:56 AM, ast wrote: Consider the following to_bytes method from integer class: int.to_bytes(length, byteorder, *, signed=False) What doest the '*' in the arguments list means ? If you go to the online doc index page for Symbols, https://docs.python.org/3/genindex-Symbols.html the

Re: Meaning of * in the function arguments list

2014-10-29 Thread ast
"Peter Otten" <__pete...@web.de> a écrit dans le message de news:mailman.15291.1414574006.18130.python-l...@python.org... A bare * indicates that the arguments that follow it are keyword-only: ok, thx -- https://mail.python.org/mailman/listinfo/python-list

Re: Meaning of * in the function arguments list

2014-10-29 Thread Peter Otten
ast wrote: > Consider the following to_bytes method from integer class: > > int.to_bytes(length, byteorder, *, signed=False) > > What doest the '*' in the arguments list means ? A bare * indicates that the arguments that follow it are keyword-only: >>> def f(a, b=2, *, c=3): ... print("a =

Meaning of * in the function arguments list

2014-10-29 Thread ast
Hi Consider the following to_bytes method from integer class: int.to_bytes(length, byteorder, *, signed=False) What doest the '*' in the arguments list means ? -- https://mail.python.org/mailman/listinfo/python-list

Re: ALL function arguments in a common dictionary

2013-04-24 Thread Fábio Santos
out_dict.update(locals()[keywords]) ... return out_dict ... >>> func(1,2, gah=123) {'a': 1, 'c': 3, 'b': 2, 'gah': 123} >>> On Wed, Apr 24, 2013 at 2:36 PM, Wolfgang Maier wrote: > Hi everybody, > what is the recommended way

ALL function arguments in a common dictionary

2013-04-24 Thread Wolfgang Maier
Hi everybody, what is the recommended way of stuffing *all* function arguments (not just the ones passed by **kwargs) into a common dictionary? The following sort of works when used as the first block in a function: try: kwargs.update(locals()) except NameError: kwargs = locals().copy

Re: Directly calling python's function arguments dispatcher

2010-12-13 Thread Pascal Chambon
Le 12/12/2010 23:41, Peter Otten a écrit : Pascal Chambon wrote: I've encountered several times, when dealing with adaptation of function signatures, the need for explicitly resolving complex argument sets into a simple variable mapping. Explanations. Consider that function: def foo(a1,

Re: Directly calling python's function arguments dispatcher

2010-12-12 Thread Peter Otten
Pascal Chambon wrote: > I've encountered several times, when dealing with adaptation of function > signatures, the need for explicitly resolving complex argument sets into > a simple variable mapping. Explanations. > > > Consider that function: > > def foo(a1, a2, *args, **kwargs): > pass

Directly calling python's function arguments dispatcher

2010-12-12 Thread Pascal Chambon
Hello I've encountered several times, when dealing with adaptation of function signatures, the need for explicitly resolving complex argument sets into a simple variable mapping. Explanations. Consider that function: def foo(a1, a2, *args, **kwargs): pass calling foo(1, a2=2, a3=3) wi

Re: Vertical line in function arguments

2010-03-27 Thread Andrej Mitrovic
Well I hate it when this happens. I ask a question, and literally 2 seconds later I bump into the answer. This explains it a bit: http://docs.python.org/library/stdtypes.html#bit-string-operations-on-integer-types -- http://mail.python.org/mailman/listinfo/python-list

Vertical line in function arguments

2010-03-27 Thread Andrej Mitrovic
There is this peace of code in a 3rd party module: MidiIn.SetFilter(pypm.FILT_ACTIVE | pypm.FILT_CLOCK | pypm.FILT_PITCHBEND | pypm.FILT_NOTE) What are the vertical lines in a function call such as this? This actually calls a function from a Pyrex module that was compiled int

Re: Writing to function arguments during execution

2009-10-14 Thread Dave Angel
John O'Hagan wrote: Thanks, sockets are the way to go for this and surprisingly easy to use once you get your head around them. I tried Rhodri's suggested approach but for now I used the original terminal for both starting the program and entering new options (still via raw_input) and a new t

Re: Writing to function arguments during execution

2009-10-13 Thread John O'Hagan
On Mon, 12 Oct 2009, Rhodri James wrote: > On Sun, 11 Oct 2009 14:18:25 +0100, John O'Hagan > > wrote: > > Now I can change the output of the "work" function while it's running via > > raw_input(). However it's very crude, not least because the terminal > > echo of > > the new options is interspe

Re: Writing to function arguments during execution

2009-10-11 Thread Rhodri James
On Sun, 11 Oct 2009 14:18:25 +0100, John O'Hagan wrote: Now I can change the output of the "work" function while it's running via raw_input(). However it's very crude, not least because the terminal echo of the new options is interspersed with the output of the program. In future I hope t

Writing to function arguments during execution

2009-10-11 Thread John O'Hagan
I'm writing a (music-generating) program incorporating a generator function which takes dictionaries as its arguments. I want to be able to change the values of the arguments while the program is running. I have it working as in this toy example (python 2.5): from sys import argv from threadin

Re: defaults for function arguments bound only once(??)

2009-10-04 Thread Simon Forman
On Sun, Oct 4, 2009 at 2:29 AM, horos11 wrote: > All, > > Another one, this time a bit shorter. > > It looks like defaults for arguments are only bound once, and every > subsequent call reuses the first reference created. Hence the > following will print '[10,2]' instead of the expected '[1,2]'. >

Re: defaults for function arguments bound only once(??)

2009-10-03 Thread Chris Rebert
On Sat, Oct 3, 2009 at 11:29 PM, horos11 wrote: > All, > > Another one, this time a bit shorter. > > It looks like defaults for arguments are only bound once, and every > subsequent call reuses the first reference created. Hence the > following will print '[10,2]' instead of the expected '[1,2]'.

defaults for function arguments bound only once(??)

2009-10-03 Thread horos11
All, Another one, this time a bit shorter. It looks like defaults for arguments are only bound once, and every subsequent call reuses the first reference created. Hence the following will print '[10,2]' instead of the expected '[1,2]'. Now my question - exactly why is 'default_me()' only called

Re: Function arguments

2009-01-26 Thread brasse
On Jan 26, 10:39 am, Chris Rebert wrote: > On Mon, Jan 26, 2009 at 1:34 AM, brasse wrote: > > On Jan 26, 10:11 am, Chris Rebert wrote: > >> On Mon, Jan 26, 2009 at 1:03 AM, brasse wrote: > >> > Hello! > > >> > Is there any way that I can get at all the arguments passed to a > >> > function as a

Re: Function arguments

2009-01-26 Thread Chris Rebert
On Mon, Jan 26, 2009 at 1:34 AM, brasse wrote: > On Jan 26, 10:11 am, Chris Rebert wrote: >> On Mon, Jan 26, 2009 at 1:03 AM, brasse wrote: >> > Hello! >> >> > Is there any way that I can get at all the arguments passed to a >> > function as a map without using keyword arguments? >> >> > def foo

Re: Function arguments

2009-01-26 Thread brasse
On Jan 26, 10:11 am, Chris Rebert wrote: > On Mon, Jan 26, 2009 at 1:03 AM, brasse wrote: > > Hello! > > > Is there any way that I can get at all the arguments passed to a > > function as a map without using keyword arguments? > > > def foo(a, b, c): > >    # Can I access all the arguments in a c

Re: Function arguments

2009-01-26 Thread Diez B. Roggisch
brasse schrieb: Hello! Is there any way that I can get at all the arguments passed to a function as a map without using keyword arguments? def foo(a, b, c): # Can I access all the arguments in a collection somewhere? I'm mainly curious since I have stumbled on to some cases where it might

Re: Function arguments

2009-01-26 Thread Chris Rebert
On Mon, Jan 26, 2009 at 1:03 AM, brasse wrote: > Hello! > > Is there any way that I can get at all the arguments passed to a > function as a map without using keyword arguments? > > def foo(a, b, c): ># Can I access all the arguments in a collection somewhere? You can use positional arguments

Re: Function arguments

2009-01-26 Thread Erik Max Francis
brasse wrote: Is there any way that I can get at all the arguments passed to a function as a map without using keyword arguments? def foo(a, b, c): # Can I access all the arguments in a collection somewhere? I'm mainly curious since I have stumbled on to some cases where it might have been

Function arguments

2009-01-26 Thread brasse
Hello! Is there any way that I can get at all the arguments passed to a function as a map without using keyword arguments? def foo(a, b, c): # Can I access all the arguments in a collection somewhere? I'm mainly curious since I have stumbled on to some cases where it might have been nice to

Re: Questions about remembering and caching function arguments

2007-11-12 Thread Aurélien Campéas
thebjorn a écrit : > On Nov 12, 1:05 am, "Anand Patil" <[EMAIL PROTECTED]> > wrote: >> Hi all, >> >> I have two questions about a class, which we'll call MyWrapperClass, >> in a package to which I'm contributing. >> >> 1) MyWrapperClass wraps functions. Each instance has an attribute >> called 'val

Re: Questions about remembering and caching function arguments

2007-11-11 Thread thebjorn
On Nov 12, 1:05 am, "Anand Patil" <[EMAIL PROTECTED]> wrote: > Hi all, > > I have two questions about a class, which we'll call MyWrapperClass, > in a package to which I'm contributing. > > 1) MyWrapperClass wraps functions. Each instance has an attribute > called 'value' and a method called 'eval'

Questions about remembering and caching function arguments

2007-11-11 Thread Anand Patil
Hi all, I have two questions about a class, which we'll call MyWrapperClass, in a package to which I'm contributing. 1) MyWrapperClass wraps functions. Each instance has an attribute called 'value' and a method called 'eval', which calls the wrapped function. An instance D that depends on instan

Function arguments [was: help]

2007-04-13 Thread Steve Holden
pierre-yves guido wrote: > hello (I hope my english is not so bad), > Your English is quite good. In future, though, please try to make your subject line say a bit more about the problem - we *all* need help! > I'm doing a training course and I'm a newbie in Python. My problem : > I have a form,

Re: Mutability of function arguments?

2005-12-08 Thread Fredrik Lundh
Mike Meyer wrote: > Your description of "passes references by value" is a description of > call by reference. C passes all arguments by value, to pass a > reference, the C programmer creates the reference to the value "by > hand", then dereferences it by hand at the other end. So C's > "call-by-re

Re: Mutability of function arguments?

2005-12-08 Thread Mike Meyer
Kent Johnson <[EMAIL PROTECTED]> writes: > Mike Meyer wrote: >> "ex_ottoyuhr" <[EMAIL PROTECTED]> writes: >> >>>I'm trying to create a function that can take arguments, say, foo and >>>bar, and modify the original copies of foo and bar as well as its local >>>versions -- the equivalent of C++ funct

Re: Mutability of function arguments?

2005-12-08 Thread Kent Johnson
Mike Meyer wrote: > "ex_ottoyuhr" <[EMAIL PROTECTED]> writes: > >>I'm trying to create a function that can take arguments, say, foo and >>bar, and modify the original copies of foo and bar as well as its local >>versions -- the equivalent of C++ funct(&foo, &bar). > > > C++'s '&' causes an argum

Re: Mutability of function arguments?

2005-12-08 Thread bruno at modulix
ex_ottoyuhr wrote: > I'm trying to create a function that can take arguments, say, foo and > bar, and modify the original copies of foo and bar as well as its local > versions -- the equivalent of C++ funct(&foo, &bar). This is already what you have. In Python, all you have are references to objec

Re: Mutability of function arguments?

2005-12-07 Thread Mike Meyer
[EMAIL PROTECTED] writes: >> Except "trick" is a poor word choice. Nobody is playing a trick on >> them - they just don't understand what is going on. > oops, never thought about the negative meaning of it, it is just meant > as "not behave as expected", what would be the word you use then ? Surp

Re: Mutability of function arguments?

2005-12-07 Thread bonono
Mike Meyer wrote: > Except "trick" is a poor word choice. Nobody is playing a trick on > them - they just don't understand what is going on. > oops, never thought about the negative meaning of it, it is just meant as "not behave as expected", what would be the word you use then ? -- http://mail.

Re: Mutability of function arguments?

2005-12-07 Thread Mike Meyer
[EMAIL PROTECTED] writes: > Mike Meyer wrote: >> [EMAIL PROTECTED] writes: >> > Mike Meyer wrote: >> >> "ex_ottoyuhr" <[EMAIL PROTECTED]> writes: >> >> > I'm trying to create a function that can take arguments, say, foo and >> >> > bar, and modify the original copies of foo and bar as well as its l

Re: Mutability of function arguments?

2005-12-07 Thread bonono
Mike Meyer wrote: > [EMAIL PROTECTED] writes: > > Mike Meyer wrote: > >> "ex_ottoyuhr" <[EMAIL PROTECTED]> writes: > >> > I'm trying to create a function that can take arguments, say, foo and > >> > bar, and modify the original copies of foo and bar as well as its local > >> > versions -- the equi

Re: Mutability of function arguments?

2005-12-07 Thread Carl J. Van Arsdall
> > And, indeed, would that approach work? Would declaring: > > class FooWrapper : > __init__(fooToLoad) : > self.foo = fooToLoad > > mean that I could now declare a FooWrapper holding a foo, pass the > FooWrapper to a function, and have the function conclude with the foo > within the

Re: Mutability of function arguments?

2005-12-07 Thread Alex Martelli
Mike Meyer <[EMAIL PROTECTED]> wrote: > > Many people from C/C++ background would be tricked for this situation. > > That's because they don't understand binding. Any language that has > bindings instead of has assignments will "trick" them this way. ...Java being probably the most popular examp

Re: Mutability of function arguments?

2005-12-07 Thread Mike Meyer
[EMAIL PROTECTED] writes: > Mike Meyer wrote: >> "ex_ottoyuhr" <[EMAIL PROTECTED]> writes: >> > I'm trying to create a function that can take arguments, say, foo and >> > bar, and modify the original copies of foo and bar as well as its local >> > versions -- the equivalent of C++ funct(&foo, &bar)

Re: Mutability of function arguments?

2005-12-07 Thread Brett g Porter
ex_ottoyuhr wrote: > I'm trying to create a function that can take arguments, say, foo and > bar, and modify the original copies of foo and bar as well as its local > versions -- the equivalent of C++ funct(&foo, &bar). > > I've looked around on this newsgroup and elsewhere, and I gather that > th

Re: Mutability of function arguments?

2005-12-07 Thread Fredrik Lundh
"ex_ottoyuhr" wrote: > I've looked around on this newsgroup and elsewhere, and I gather that > this is a very common concern in Python, but one which is ordinarily > answered with "No, you can't. Neat, huh?" A few websites, newsgroup > posts, etc. have recommended that one ask for a more "Pythonic

Re: Mutability of function arguments?

2005-12-07 Thread bonono
Mike Meyer wrote: > "ex_ottoyuhr" <[EMAIL PROTECTED]> writes: > > I'm trying to create a function that can take arguments, say, foo and > > bar, and modify the original copies of foo and bar as well as its local > > versions -- the equivalent of C++ funct(&foo, &bar). > > C++'s '&' causes an argum

Re: Mutability of function arguments?

2005-12-07 Thread Mark Tolonen
"ex_ottoyuhr" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'm trying to create a function that can take arguments, say, foo and > bar, and modify the original copies of foo and bar as well as its local > versions -- the equivalent of C++ funct(&foo, &bar). > > I've looked around

Re: Mutability of function arguments?

2005-12-07 Thread Mike Meyer
"ex_ottoyuhr" <[EMAIL PROTECTED]> writes: > I'm trying to create a function that can take arguments, say, foo and > bar, and modify the original copies of foo and bar as well as its local > versions -- the equivalent of C++ funct(&foo, &bar). C++'s '&' causes an argument to be passed by reference.

Re: Mutability of function arguments?

2005-12-07 Thread ex_ottoyuhr
(Re. mutability question:) Update, never mind. I found that the FooWrapper solution isn't so bad after all -- and even better is putting the variable in question in a different module entirely. However, anyone who wants to answer the question is still welcome to. Sorry to be a bother, and to have

Mutability of function arguments?

2005-12-07 Thread ex_ottoyuhr
I'm trying to create a function that can take arguments, say, foo and bar, and modify the original copies of foo and bar as well as its local versions -- the equivalent of C++ funct(&foo, &bar). I've looked around on this newsgroup and elsewhere, and I gather that this is a very common concern in

Re: expanding dictionary to function arguments

2005-11-02 Thread Bengt Richter
On 1 Nov 2005 17:17:00 -0800, "Noah" <[EMAIL PROTECTED]> wrote: >I have a dictionary that I would like to expand to satisfy a >function's agument list. I can used the ** syntax to pass a dictionary, >but >this only works if each key in the dictionary matches an argument. >I cannot pass a dictionar

Re: expanding dictionary to function arguments

2005-11-02 Thread bruno at modulix
Noah wrote: > Bruno Desthuilliers a écrit : > >>Noah a écrit : >>If you have control over the API functions declarations, makes them so: >>def my_api_func(arg1='', arg2='whatever', **kwargs): >> code_here > > > Unfortunately I cannot change the API functions. > I should have mentioned that. Y

Re: expanding dictionary to function arguments

2005-11-02 Thread Noah
Bruno Desthuilliers a écrit : > Noah a écrit : > If you have control over the API functions declarations, makes them so: > def my_api_func(arg1='', arg2='whatever', **kwargs): >code_here Unfortunately I cannot change the API functions. I should have mentioned that. Yours, Noah -- http://ma

Re: expanding dictionary to function arguments

2005-11-02 Thread Bruno Desthuilliers
Noah a écrit : > I have a dictionary that I would like to expand to satisfy a > function's agument list. I can used the ** syntax to pass a dictionary, > but > this only works if each key in the dictionary matches an argument. > I cannot pass a dictionary that has more keys than the function has >

expanding dictionary to function arguments

2005-11-02 Thread Noah
I have a dictionary that I would like to expand to satisfy a function's agument list. I can used the ** syntax to pass a dictionary, but this only works if each key in the dictionary matches an argument. I cannot pass a dictionary that has more keys than the function has arguments. # Example 1 - T

Re: Default function arguments behaving badly

2005-08-24 Thread [EMAIL PROTECTED]
That works perfectly - Thanks! I'm always getting tripped up by the mutability of lists, I should really learn to look out for it more... -- http://mail.python.org/mailman/listinfo/python-list

Re: Default function arguments behaving badly

2005-08-24 Thread Paul McNett
[EMAIL PROTECTED] wrote: > I'm having some trouble with a function I've written in Python: > def myFunction(l1,l2,result=[]): [snipped rest of function and explanation of what it does] > Does anyone know what is going on here? Is there an easy solution? It shined out like a supernova. It has to

Re: Default function arguments behaving badly

2005-08-24 Thread rafi
[EMAIL PROTECTED] wrote: > Hi hi > I'm having some trouble with a function I've written in Python: > > def myFunction(l1,l2,result=[]): > index=0 > for i in l1: > result.append([]) > if type(i)==list: > myFunction(i,l2,result[index]) > else: >

Default function arguments behaving badly

2005-08-24 Thread [EMAIL PROTECTED]
Hi I'm having some trouble with a function I've written in Python: def myFunction(l1,l2,result=[]): index=0 for i in l1: result.append([]) if type(i)==list: myFunction(i,l2,result[index]) else: for j in l2: result[index].appe

Non-anonymous function arguments

2005-04-28 Thread cjm_usenet
I had an idea for passing functions as arguments: Allow a block syntax (like with class definition) for keyword arguments, attached to a statement that includes a function call but doesn't need the block for something else (like loops and ifs). Apologies for the contrived examples. squares = map

Re: wxwindows event function arguments

2005-04-07 Thread Greg Krohn
lotmr wrote: I have a windows launch bar application that sits in the system tray. What I want to do is when i click on a button in the launch menu, it calls the event which then calls 'OnLaunch('path')' this does not seem possible. When I change 'OnLaunch(self, event)' to 'OnLaunch(self, event, pa

wxwindows event function arguments

2005-04-07 Thread lotmr
I have a windows launch bar application that sits in the system tray. What I want to do is when i click on a button in the launch menu, it calls the event which then calls 'OnLaunch('path')' this does not seem possible. When I change 'OnLaunch(self, event)' to 'OnLaunch(self, event, path)' it says

Re: Default function arguments, KURL::cleanPath() -- a bindings bug?

2005-03-08 Thread Frans Englich
Ups, that was meant to go to the pykde list. Sorry, Frans -- http://mail.python.org/mailman/listinfo/python-list

RE: Default function arguments, KURL::cleanPath() -- a bindings bug?

2005-03-07 Thread Delaney, Timothy C (Timothy)
Frans Englich wrote: > Apparently, cleanPath /requires/ a boolean argument, but the C++ > function definition says: > > void cleanPath(bool cleanDirSeparator = true); Most likely that cleanPath's default parameter hasn't been declared to *Python*. If so, I expect this is a KURL bug. Raise a bu

Default function arguments, KURL::cleanPath() -- a bindings bug?

2005-03-07 Thread Frans Englich
Hello, I've stumbled over a behavior related to default function arguments which appears to be a bug, from what I can tell. See this snippet: >>> from kdecore import KURL >>> u = KURL( "http://www.example.org/test/../"; ) >>> u.cleanPath() Traceback

Re: Dynamically pass a function arguments from a dict

2005-02-24 Thread Scott David Daniels
Mark McEahern wrote: Dan Eloff wrote: How can you determine that func2 will only accept bar and zoo, but not foo and call the function with bar as an argument? Let Python answer the question for you: ... Please be aware the "normal" way to do this is go ahead and call the function. Many "functio

Re: Dynamically pass a function arguments from a dict

2005-02-24 Thread Nick Coghlan
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. Running startup script Py> import inspect Py> help(inspect.getargspec) Help on function getargspec in module inspect: getargspec(func) Get the name

Re: Dynamically pass a function arguments from a dict

2005-02-23 Thread Dan Eloff
Awesome, wrapping that into a function: def getargs(func): numArgs = func.func_code.co_argcount names = func.func_code.co_varnames return names[:numArgs] short, concise, and it works :) variables declared inside the function body are also in co_varnames but after the arguments only it s

Re: Dynamically pass a function arguments from a dict

2005-02-23 Thread Mark McEahern
Dan Eloff wrote: How can you determine that func2 will only accept bar and zoo, but not foo and call the function with bar as an argument? Let Python answer the question for you: >>> def func2(bar='a', zoo='b'): ... pass ... >>> for name in dir(func2): ... print '%s: %s' % (name, getattr(func2, na

Dynamically pass a function arguments from a dict

2005-02-23 Thread Dan Eloff
You can take a dictionary of key/value pairs and pass it to a function as keyword arguments: def func(foo,bar): print foo, bar args = {'foo':1, 'bar':2} func(**args) will print "1 2" But what if you try passing those arguments to a function def func2(bar,zoo=''): print bar, zoo H

RE: Class introspection and dynamically determining function arguments

2005-01-24 Thread Mark English
Thanks for the pointers to traits, BasicProperty, and harold fellermann's sample code... --- The information contained in this e-mail is confidential and solely for the intended addressee(s). Unauthorised reproduction, disclosur

Re: Class introspection and dynamically determining function arguments

2005-01-22 Thread Mike C. Fletcher
Bengt Richter wrote: On Fri, 21 Jan 2005 20:23:58 -0500, "Mike C. Fletcher" <[EMAIL PROTECTED]> wrote: On Thu, 20 Jan 2005 11:24:12 -, "Mark English" <[EMAIL PROTECTED]> wrote: ... Does the BasicProperty base class effectively register itself as an observer of subclass properties and

Re: Class introspection and dynamically determining function arguments

2005-01-22 Thread Alex Martelli
Diez B. Roggisch <[EMAIL PROTECTED]> wrote: > Nick Coghlan wrote: > > > > If this only has to work for classes created for the purpose (rather than > > for an arbitrary class): > > Certainly a step into the direction I meant - but still missing type > declarations. And that's what at least I'd l

Re: Class introspection and dynamically determining function arguments

2005-01-22 Thread Bengt Richter
On Fri, 21 Jan 2005 20:23:58 -0500, "Mike C. Fletcher" <[EMAIL PROTECTED]> wrote: > >>On Thu, 20 Jan 2005 11:24:12 -, "Mark English" <[EMAIL PROTECTED]> wrote: >> >> >> >>>I'd like to write a Tkinter app which, given a class, pops up a >>>window(s) with fields for each "attribute" of that c

Re: Class introspection and dynamically determining function arguments

2005-01-21 Thread Mike C. Fletcher
On Thu, 20 Jan 2005 11:24:12 -, "Mark English" <[EMAIL PROTECTED]> wrote: I'd like to write a Tkinter app which, given a class, pops up a window(s) with fields for each "attribute" of that class. The user could enter values for the attributes and on closing the window would be returned an i

Re: Class introspection and dynamically determining function arguments

2005-01-21 Thread Bengt Richter
On Thu, 20 Jan 2005 11:24:12 -, "Mark English" <[EMAIL PROTECTED]> wrote: >I'd like to write a Tkinter app which, given a class, pops up a >window(s) with fields for each "attribute" of that class. The user could >enter values for the attributes and on closing the window would be >returned an

RE: Class introspection and dynamically determining function arguments

2005-01-21 Thread Mark English
Diez B. Roggisch wrote: > According to this > http://www-106.ibm.com/developerworks/library/l-pyint.html > > not really - and there are no special moduls neccessary, as > everything is at your hands using __dict__ and so on. Thanks for the link. I'd read that article but found it was too introd

Re: Class introspection and dynamically determining function arguments

2005-01-21 Thread Nick Coghlan
Diez B. Roggisch wrote: Nick Coghlan wrote: If this only has to work for classes created for the purpose (rather than for an arbitrary class): Certainly a step into the direction I meant - but still missing type declarations. And that's what at least I'd like to see - as otherwise you don't know w

RE: Class introspection and dynamically determining function arguments

2005-01-21 Thread Diez B. Roggisch
> The classes I'm dealing with do have attributes since they're > C-Extension types with attributes provided in the "tp_getset" slot. So > this is one case where I can query the class for attributes without > having to create an instance. Thanks for making me think of that, since > looking in the c

RE: Class introspection and dynamically determining function arguments

2005-01-21 Thread Mark English
> From: "Mark English" <[EMAIL PROTECTED]> > > I'd like to write a Tkinter app which, given a class, pops up a > window(s) with fields for each "attribute" of that class. The > user could enter values for the attributes and on closing the > window would be returned an instance of the class. The

Re: Class introspection and dynamically determining function arguments

2005-01-20 Thread Diez B. Roggisch
Nick Coghlan wrote: > > If this only has to work for classes created for the purpose (rather than > for an arbitrary class): > Certainly a step into the direction I meant - but still missing type declarations. And that's what at least I'd like to see - as otherwise you don't know what kind of ed

Re: Class introspection and dynamically determining function arguments

2005-01-20 Thread Nick Coghlan
Diez B. Roggisch wrote: Mark English wrote: As youself already mentioned that maybe you have to impose certain prerequisites, you maybe want to extend this to the point where for each class you want to make dynamically instantiatable you need some declaration. This of course depends on your desired

Re: Class introspection and dynamically determining function arguments

2005-01-20 Thread Diez B. Roggisch
Mark English wrote: > The only way I can imagine to do this is to create an instance of the > class in question, and then start poking around in its attributes > dictionary (initially just using dir). So firstly, if there is instead a > way to do this without creating an instance I'd be interested

Class introspection and dynamically determining function arguments

2005-01-20 Thread Mark English
I'd like to write a Tkinter app which, given a class, pops up a window(s) with fields for each "attribute" of that class. The user could enter values for the attributes and on closing the window would be returned an instance of the class. The actual application I'm interested in writing would eithe

late evaluation of function arguments (WAS: expression form of one-to-many dict?)

2004-12-19 Thread Steven Bethard
; . ... print unpack(x) . ... . >>> f(C("created")) . created . f . <__main__.C object at 0x01140790> . >>> f(C("created") for _ in [1]) . f . created . <__main__.C object at 0x0114F810> Of course, the syntax here isn