Results 1 to 2 of 2

Thread: Regular expression in python

  1. #1
    Join Date
    Sep 2008
    Beans
    16

    Regular expression in python

    Hi,

    in my off-time lately i have been learning python and pygtk to make an application. well anyway i got stuck on a RE problem if anyone could please help

    here where it gets stuck (actually dosent do anything):

    Code:
    clean_sources_lists = [item for item in listOfSrc if re.search(pattern, item)]
    in context:

    Code:
    def cleanSrcList(self, listOfSrc):
    		pattern = '^deb.'
    		clean_sources_lists = [item for item in listOfSrc if re.search(pattern, item)]

    thanks for helping

  2. #2
    Join Date
    May 2006
    Beans
    1,787

    Re: Regular expression in python

    Quote Originally Posted by lordgafal View Post
    Hi,

    in my off-time lately i have been learning python and pygtk to make an application. well anyway i got stuck on a RE problem if anyone could please help

    here where it gets stuck (actually dosent do anything):

    Code:
    clean_sources_lists = [item for item in listOfSrc if re.search(pattern, item)]
    in context:

    Code:
    def cleanSrcList(self, listOfSrc):
    		pattern = '^deb.'
    		clean_sources_lists = [item for item in listOfSrc if re.search(pattern, item)]

    thanks for helping
    I think you need to show listOfSrc too.

    This trivial test succeeds, anyway:

    Code:
    >>> import re
    >>> [i for i in ["deb.hej", "hopp"] if re.search("^deb.", i)]
    ['deb.hej']
    >>>
    But maybe you forgot to return the clean_sources_list from the function?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •