[Tutor] Decorator listing

Emile van Sebille emile at fenx.com
Wed Jul 28 00:13:06 CEST 2010


On 7/27/2010 1:11 PM Mary Morris said...
> I'm writing a program with python that compiles a list of decorators from my
> company's source code.  I'm new to python and need help with the following:
> I'm trying to make the program find ".com" in any lines and not include them
> in the list of decorators that gets returned.  THis is because I had the
> program look for the @ symbol to find the decorators and it returned email
> addresses in the list.

You can probably sidestep this issue by looking for the @ symbol in the 
first non-whitespace position in the line, rather than in any position 
of the line.

IE, instead of something like:

   if "@" in line:

...try something more like:

   if line.strip().startswith("@"):


This way you won't pick up the email addresses at all, and won't 
subsequently need to filter them out of your results set.

HTH,

Emile





More information about the Tutor mailing list