On Friday 23 July 2010 11:53 PM, Mary Morris wrote:
I'm trying to compile a list of decorators from the source code at my office.
I did this by doing a

candidate_line.find("@")

How about using something like

candidate_line.strip.startswith('@') and calculate_line.find('.') == -1

There are few more cases where above may fail. In that case you may want to use re module instead.
e.g.
@test_decorator # this is test comment.


because all of our decorators start with the @ symbol. The problem I'm having is that the email addresses that are included in the comments are getting included in the list that is getting returned. I was thinking I could do a candidate_line.find(".com") to set the email addresses apart, but how do I tell the computer to not include the lines it finds with ".com" in them in the list?

The part of my code that I'm hoping to include this in 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("#")
                #if () is in the last spot
                if i == -1:
#if () is in the last spot and the decorator is in a comment
                        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 comment
                        if j == 0:
                                candidate_line = candidate_line[2:]
#if there are not ()'s and the decorator isn't in a comment
                        elif j != 0:
                                candidate_line = candidate_line[1:]
 elif candidate_line.find(".com"):
                        candidate_line != candidate_line
                return_decorators.append((line_number, candidate_line))
        return return_decorators
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to