[mod_python] python print

tpc at csua.berkeley.edu tpc at csua.berkeley.edu
Mon Jun 9 11:39:10 EST 2003


Hello, I have a script meant to be run from the command line that for each
command line argument, iterates through the characters, returns the value
from a dictionary, and prints out the joined string with no spaces:

<code>
#!/usr/bin/env python

import sys

dict1 = {
            '0' : 'zero',
            '1' : 'one',
            '2' : 'two',
            '3' : 'three',
            '4' : 'four',
            '5' : 'five',
            '6' : 'six',
            '7' : 'seven',
            '8' : 'eight',
            '9' : 'nine'
        }

for argument in sys.argv[1:]:
    print ''.join([dict1[character] for character in argument])
    print '\n'

</code>

I know 'print' and 'echo' are not valid in mod python, and I have tried:

<code>
def convert(numbers):
    for argument in numbers:
        w = ''.join([dict1[character] for character in argument])
        return w
</code>

although 'return' seems to exit after the first character.  I have also
tried:

<code>
x = []
def convert(numbers):
    for argument in numbers:
        x.append([dict1[character] for character in argument])
    return x
</code>

although I get a KeyError.
Is there a mod python alternative to 'print' so I may simply substitute ?



More information about the Mod_python mailing list