[FRPythoneers] Porting perl to python

Erick Bodine erick at allocity.com
Fri Jul 11 15:29:51 MDT 2003


Howdy Jake,

Either your suggestion or Jake Dietrich's solution will work.

Many thanks,

--ERick


-----Original Message-----
From: Jake Edge [mailto:jake at edge2.net] 
Sent: Friday, July 11, 2003 11:45 AM
To: frpythoneers at lists.community.tummy.com
Subject: Re: [FRPythoneers] Porting perl to python


On Fri, Jul 11, 2003 at 11:32:15AM -0600, Erick Bodine wrote:
> I have tried various manipulations using the dir() and callable() 
> builtins to no avail.  I think that 'recipe' 15.3 in the Python 
> cookbook might contain some clues (some manipulation around 
> __import__) but I am not really familiar w/ how this works in Python.
> 
> Any help would be appreciated.
> 
> # Perl code
> my (@tests) = qw(domain_administrator
> 		 scrubber_registry_size
> 		 pr2051);
> 
> foreach my $test_name ( @tests ) {
>   print "$test_name ", ("." x (26 - length($test_name))), " ";
>   my ($rc, $reason) = &$test_name;
> }
> 		 
> # Python code
> def_list = ['test1', 'test2', 'test3]
> for f in def_list:
> 	f()			# This won't work because f is not
> callable

Hi Erick,

Perhaps instead of strings, you just want to put function references in
the list as the following illustrates:

def foo(bar):
    print bar

def bar(xyz):
    print xyz

fn_list = [ foo, bar ]
for i in fn_list:
    i(42);

would that work for you?

jake

-- 
Jake Edge - jake at edge2.net
_______________________________________________
This message sent by the FRPythoneers mailing list.
Unsubscribe: echo unsubscribe |
FRPythoneers-request at lists.community.tummy.com
URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers



More information about the FRPythoneers mailing list