[Tutor] I'm drawing a blank here.. help please

Jeff Shannon jeff@ccvcorp.com
Wed, 21 Aug 2002 09:54:30 -0700


S A wrote:

>      def __init__(self, html, t):
>         self.html = html
>         self.t = t
>      def crop(self):
>            story = "(?sx)%s.+%s" % ("<!--Storytext-->", "<!--/Storytext-->")
>            newhtml = re.findall(story, self.html)

I notice you have inconsistent indentation for these two methods.  That *shouldn't* be an actual error (and you should be getting a SyntaxError instead of a NameError if it was), but it's not terribly good style...


> Traceback (most recent call last):
>   File "./fnewsupdate.py", line 3, in ?
>     from update import *
>   File "./update.py", line 63, in ?
>     class TextExtractor:
>   File "./update.py", line 73, in TextExtractor
>     newhtml = re.findall(story, self.html)
> NameError: name 'story' is not defined

You're sure that you cut&pasted the exact code that you're importing?  If so, perhaps you should show us a bit more of the code.  Other than the indentation issue, I don't see anything glaringly wrong...

However, there's another "bad style" point here -- I see that you're using 'from update import *'.  This form of import may seem easier, but it's not generally recommended.  It becomes very easy for imported names to shadow each other, leading to strange errors, and it's difficult to track where a
particular name originates.  There are a few toolkit packages (Tkinter, PIL, and wxPython come to mind) that are specifically designed to be fairly safe to use this way, but they are the exception rather than the rule.  I'd suggest going through your program, eliminating the wildcard imports, and using
fully qualified names -- i.e., change 'from update import *' to 'import update' and change 'TextExtractor' to 'update.TextExtractor'.  I can't think offhand of any way in which a wildcard import could be causing this particular error, but it makes other errors likely (as well as making maintenance more
difficult).

Jeff Shannon
Technician/Programmer
Credit International