[Tutor] Decorator listing

Mary Morris marris1031 at gmail.com
Tue Jul 27 22:11:18 CEST 2010

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.  What I was thinking was to do something like this:
k = candidate_line.find(".com")
if k != -1:
     candidate_line != candidate_line

The problem is that I know this won't work because ".com" can't be in the
last slot of the candidate line...  So far the part of my code that needs to
be changed looks like this...

      #parse out the names of the decorators from those lines
        return_decorators= []
        for ele in subset_lines:
                candidate_line, line_number = ele
                candidate_line = candidate_line.strip()
                i = candidate_line.find("(")
                j = candidate_line.find("#")
                k = candidate_line.find(".com")
                #if () is in the last spot
                if i == -1:
                        #if () is in the last spot and the decorator is in a
                        if j == 0:
                                #get rid of ( and #
                                candidate_line = candidate_line[2:i]
                        #if () is in the last spot and the decorator is not
in a comment
                        elif j != 0:
                                candidate_line = candidate_line[1:i]
                #if there are not ()'s in the last spot
                elif i != -1:
                        #if there are not ()'s, but the decorator is in a
                        if j == 0:
                                candidate_line = candidate_line[2:]
                        #if there are not ()'s and the decorator isn't in a
                        elif j != 0:
                                candidate_line = candidate_line[1:]
                elif k in candidate_line:
                        candidate_line != candidate_line
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100727/07683823/attachment.html>

More information about the Tutor mailing list