Re: How to handle calling functions from cli

2012-02-24 Thread Chris Angelico
On Sat, Feb 25, 2012 at 9:16 AM, Rodrick Brown wrote: > m = { 'a': 'checkDisks()', >          'b': 'checkMemSize()', >          'c': 'checkBondInterfaces()' >    } > >    runlist = [ c for c in m.keys() if c not in r.d ] >    for runable in runlist: >        eval(m[runable]) It's a reasonable tec

Re: How to handle calling functions from cli

2012-02-24 Thread Chris Rebert
On Fri, Feb 24, 2012 at 2:16 PM, Rodrick Brown wrote: > I have a bunch of sub routines that run independently to perform various > system checks on my servers. I wanted to get an opinion on the following code > I have about 25 independent checks and I'm adding the ability to disable > certain c

How to handle calling functions from cli

2012-02-24 Thread Rodrick Brown
I have a bunch of sub routines that run independently to perform various system checks on my servers. I wanted to get an opinion on the following code I have about 25 independent checks and I'm adding the ability to disable certain checks that don't apply to certain hosts. m = { 'a': 'checkDis

Re: Calling functions: Why this complicated ?

2009-08-01 Thread lkcl
On Jul 14, 11:31 pm, Chris Rebert wrote: > On Tue, Jul 14, 2009 at 1:40 PM, Mohan Parthasarathy > wrote: > > Hi, > > I am a newbie. I am reading > >http://www.network-theory.co.uk/docs/pytut/KeywordArguments.html > > Defining a function with "N" arguments and calling them in "M" different > > way

Re: Calling functions: Why this complicated ?

2009-07-15 Thread Jeremiah Dodds
On Wed, Jul 15, 2009 at 11:54 AM, Tim Rowe wrote: > > Curiously, I never use the all-named style in Python, whereas it's my > normal style in Ada. I shall now enter a period of self-refelection to > try to work out why I am so inconsistent :-) > > > I use it for functions that only (or mostly) ha

Re: Calling functions: Why this complicated ?

2009-07-15 Thread Tim Rowe
2009/7/15 Jeremiah Dodds : > As a hopefully semi-informative aside, I've been writing python code for a > few years now, and I regularly use all four forms of argument passing listed > above. Curiously, I never use the all-named style in Python, whereas it's my normal style in Ada. I shall now en

Re: Calling functions: Why this complicated ?

2009-07-15 Thread Jeremiah Dodds
On Wed, Jul 15, 2009 at 1:42 AM, Mohan Parthasarathy wrote: > So, all four of them above has its use cases in practice i guess. > > thanks > mohan > As a hopefully semi-informative aside, I've been writing python code for a few years now, and I regularly use all four forms of argument passing lis

Re: Calling functions: Why this complicated ?

2009-07-14 Thread Mohan Parthasarathy
Chris, Thanks for your clarifications > > I am a newbie. I am reading > > http://www.network-theory.co.uk/docs/pytut/KeywordArguments.html > > Defining a function with "N" arguments and calling them in "M" different > > ways. Why does it have to be this complicated ? I like the idea of > calling

Re: Calling functions: Why this complicated ?

2009-07-14 Thread Chris Rebert
On Tue, Jul 14, 2009 at 1:40 PM, Mohan Parthasarathy wrote: > Hi, > I am a newbie. I am reading > http://www.network-theory.co.uk/docs/pytut/KeywordArguments.html > Defining a function with "N" arguments and calling them in "M" different > ways. Why does it have to be this complicated ? I like the

Calling functions: Why this complicated ?

2009-07-14 Thread Mohan Parthasarathy
Hi, I am a newbie. I am reading http://www.network-theory.co.uk/docs/pytut/KeywordArguments.html Defining a function with "N" arguments and calling them in "M" different ways. Why does it have to be this complicated ? I like the idea of calling the function by explicitly naming the arguments, but

Re: Calling functions with dynamic arguments

2006-11-29 Thread SeanDavis12
Roberto Bonvallet wrote: > SeanDavis12 wrote: > > I have a dictionary like: > > > > {"a":1, "b":2} > > > > and I want to call a function: > > > > def func1(a=3,b=4): > >print a,b > > > > so that I get a=1,b=2, how can I go about that? > > func1(**yourdict) Thanks, Roberto. Sean -- http:

Re: Calling functions with dynamic arguments

2006-11-29 Thread Roberto Bonvallet
SeanDavis12 wrote: > I have a dictionary like: > > {"a":1, "b":2} > > and I want to call a function: > > def func1(a=3,b=4): >print a,b > > so that I get a=1,b=2, how can I go about that? func1(**yourdict) -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list

Calling functions with dynamic arguments

2006-11-29 Thread SeanDavis12
I have a dictionary like: {"a":1, "b":2} and I want to call a function: def func1(a=3,b=4): print a,b so that I get a=1,b=2, how can I go about that? Thanks, Sean -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling functions

2006-10-19 Thread Tommy Grav
That does work yes :) I just noticed that the script had another little error in it, making me believe that the function call was crooking.Cheers   TommyOn Oct 19, 2006, at 12:30 PM, Dustin J. Mitchell wrote:Tommy Grav wrote: I have a small program that goes something like thisdef funcA() : passdef

Re: Calling functions

2006-10-19 Thread Fredrik Lundh
Tommy Grav wrote: > I have a small program that goes something like this > > def funcA() : pass > def funcB() : pass > def funcC() : pass > > def determine(f): > t = f() > return t > > What I would like to do is be able to > > n = determine(funcA) > m = determine(funcB) > > But I can

Re: Calling functions

2006-10-19 Thread Dustin J. Mitchell
Tommy Grav wrote: > I have a small program that goes something like this > > def funcA() : pass > def funcB() : pass > def funcC() : pass > > def determine(f): > t = f() > return t > > What I would like to do is be able to > > n = determine(funcA) > m = determine(funcB) > > But I can't really

Calling functions

2006-10-19 Thread Tommy Grav
I have a small program that goes something like thisdef funcA() : passdef funcB() : passdef funcC() : passdef determine(f): t = f() return tWhat I would like to do is be able to n = determine(funcA)m = determine(funcB)But I can't really figure out how to do this (I think it is possible :) CheersTom

Re: calling functions style question

2006-06-06 Thread Kay Schluehr
Brian wrote: > I just have a basic style question here. Suppose you have the program: > > def foo1(): > do something > > def foo2() > do something else > > Assume that you want to call these functions at execution. Is it more > proper to call them directly like: > > foo1() > foo2() > > o

Re: calling functions style question

2006-06-06 Thread Thomas Nelson
The difference becomes clear when you import your program into another program (or the command line python editor). __name__!='__main__' when you import, so the functions will not be called if they're inside the block. This is why you see this block so often at the end of scripts; so that the scr

calling functions style question

2006-06-06 Thread Brian
I just have a basic style question here. Suppose you have the program: def foo1(): do something def foo2() do something else Assume that you want to call these functions at execution. Is it more proper to call them directly like: foo1() foo2() or in an if __name__ == "__main__": ? B

Re: calling functions

2005-08-02 Thread bruno modulix
anthonyberet wrote: > This is the first time I have tried out functions (is that the main way > of making subroutines in Python?) A function is allowed to change it's arguments and to return None, so yes, you can consider it as a 'subroutine'. > > Anyway, my function, mutate, below > > #make a

Re: calling functions

2005-08-01 Thread jepler
Without a 'global' statement, all variables which are assigned in the body of a function are local to that function. Here is an example showing that f() does not create a module-level variable, but g() does. >>> def f(): ... z = 3 ... >>> def g(): ... global z ... z = 3 ... >>> z Tr

calling functions

2005-08-01 Thread anthonyberet
This is the first time I have tried out functions (is that the main way of making subroutines in Python?) Anyway, my function, mutate, below #make a child string by randomly changing one character of the parent Def mutate(): newnum=random.randrange(27) if newnum==0:

Re: Iterate through a list calling functions

2005-06-05 Thread Kent Johnson
David Pratt wrote: > Hi Kent. Thank you for your reply. I gave this a go but get the > following traceback: > ... > result = validator(name, value) > TypeError: 'str' object is not callable > > Have put validators in list and iterate over it as in following: > > validator_list = > [is

Re: Iterate through a list calling functions

2005-06-05 Thread Kent Johnson
George Sakkis wrote: > That's a typical case for using an OO approach; just make a class for > each validator and have a single polymorphic validate method (I would > make validators __call__able instead of naming the method 'validate'): > > # Abstract Validator class; not strictly necessary but g

Re: Iterate through a list calling functions

2005-06-05 Thread David Pratt
Cool! Many thanks George. Yes this is the way to go - objects. Much better :-) On Sunday, June 5, 2005, at 02:49 PM, George Sakkis wrote: > David Pratt wrote: >> Hi. I am creating methods for form validation. Each validator has its >> own method and there quite a number of these. For each fi

Re: Iterate through a list calling functions

2005-06-05 Thread David Pratt
Hi Kent. Thank you for your reply. I gave this a go but get the following traceback: ... result = validator(name, value) TypeError: 'str' object is not callable Have put validators in list and iterate over it as in following: validator_list = [isContainedIn,isDate,isDecimal,isEma

Re: Iterate through a list calling functions

2005-06-05 Thread George Sakkis
David Pratt wrote: > Hi. I am creating methods for form validation. Each validator has its > own method and there quite a number of these. For each field, I want > to evaluate errors using one or more validators so I want to execute > the appropriate validator methods from those available. I am

Re: Iterate through a list calling functions

2005-06-05 Thread Kent Johnson
David Pratt wrote: > Hi. I am creating methods for form validation. Each validator has its > own method and there quite a number of these. For each field, I want to > evaluate errors using one or more validators so I want to execute the > appropriate validator methods from those available. I

Iterate through a list calling functions

2005-06-05 Thread David Pratt
Hi. I am creating methods for form validation. Each validator has its own method and there quite a number of these. For each field, I want to evaluate errors using one or more validators so I want to execute the appropriate validator methods from those available. I am iterating over each va

Re: calling functions across threads

2004-12-29 Thread It's me
I haven't play with the thread stuff in Python (yet) but in general terms (from a C mind), one should not expect read/write actions to be sequential across threads. I would assume the Python threads eventually goes back to some system calls for thread handling. If that were the case, you should

Re: calling functions across threads

2004-12-29 Thread Steve Holden
Steven Bethard wrote: Fernando Perez wrote: Steven Bethard wrote: Fernando Perez wrote: Steven Bethard wrote: I get the correct output, but if you run this yourself, you'll see that the numbers 1 through 10 aren't printed in sync with the writes (i.e. every half second); they're all printed at t

Re: calling functions across threads

2004-12-29 Thread Steven Bethard
Fernando Perez wrote: Steven Bethard wrote: Fernando Perez wrote: Steven Bethard wrote: I get the correct output, but if you run this yourself, you'll see that the numbers 1 through 10 aren't printed in sync with the writes (i.e. every half second); they're all printed at the end. Could someone

Re: calling functions across threads

2004-12-29 Thread Fernando Perez
Steven Bethard wrote: > Fernando Perez wrote: >> Steven Bethard wrote: >> >> >>>I get the correct output, but if you run this yourself, you'll see that >>>the numbers 1 through 10 aren't printed in sync with the writes (i.e. >>>every half second); they're all printed at the end. Could someone >

Re: calling functions across threads

2004-12-29 Thread Steven Bethard
Fernando Perez wrote: Steven Bethard wrote: I get the correct output, but if you run this yourself, you'll see that the numbers 1 through 10 aren't printed in sync with the writes (i.e. every half second); they're all printed at the end. Could someone explain to me why this happens, and how (if p

Re: calling functions across threads

2004-12-29 Thread Fernando Perez
Steven Bethard wrote: > I get the correct output, but if you run this yourself, you'll see that > the numbers 1 through 10 aren't printed in sync with the writes (i.e. > every half second); they're all printed at the end. Could someone > explain to me why this happens, and how (if possible) I can

Re: calling functions across threads

2004-12-29 Thread Steven Bethard
Thomas Rast wrote: Steven Bethard <[EMAIL PROTECTED]> writes: I get the correct output, but if you run this yourself, you'll see that the numbers 1 through 10 aren't printed in sync with the writes (i.e. every half second); they're all printed at the end. Could someone explain to me why this happe

Re: calling functions across threads

2004-12-29 Thread Thomas Rast
Steven Bethard <[EMAIL PROTECTED]> writes: > I get the correct output, but if you run this yourself, you'll see > that the numbers 1 through 10 aren't printed in sync with the writes > (i.e. every half second); they're all printed at the end. Could > someone explain to me why this happens, and ho

calling functions across threads

2004-12-29 Thread Steven Bethard
I'm playing around with some threading stuff right now, and I'm having a little trouble calling a function from one thread that affects another. Here's my setup: py> import os, threading, time py> def write(file_in, input_lines): ... for line in input_lines: ... time.sleep(0.5) ...