[FRPythoneers] Porting perl to python

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


All,

I have convinced my place of employ to move from Perl to Python and I am
currently porting the majority of the perl scripts we use to python.
One of the scripts does a health check of the test systems.  The checks
are inidividual functions that are run.  In the perl script the check
functions are added to the script and a list of check functions, then
the list of functions is then run at script runtime as anonymous
subroutines.

In the python version ideally I would import a separate module that
would contain all of the present and any future functions and then run
all the functions contained in that module.

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

--ERick



More information about the FRPythoneers mailing list