[Tutor] Functions and lists.

SA sarmstrong13@mac.com
Tue, 13 Aug 2002 16:22:47 -0500


Hi Everyone-

Ok. I'm doing something wrong here and need a little nudge in the right
direction. I have a script that begins as follows:

#!/usr/bin/env python
import re
import os
import sys
import string

print "Enter Directory: "
value = string.strip(sys.stdin.readline())
list = os.listdir("%s" % value)
l = len(list)


I then have the following function:

def input(insource):
    infile = open(value + insource, "rb")
    text = infile.read()
    infile.close()
    return text

In the main namespace I have a iteration that goes like so:

    
for i in range(l):
    input(list[i])
    substr(text)


Sorry, substr is another function that does some re on text.

The problem lies in the function input. Does return not return 'text' to the
top-level namespace so that it can be worked on by the function substr?
Because I get the following 'not defined' error:

Traceback (most recent call last):
  File "./remodpyqt.py", line 29, in ?
    substr(text)
NameError: name 'text' is not defined


I know this is probably a simple mistake on my end, I would be appreciative
of a push in the right direction.

Thanks.
SA


-- 
"I can do everything on my Mac I used to on my PC. Plus a lot more ..."
-Me