Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.roellig-ltd.de!open-news-network.org!border2.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'string': 0.09; "'.'": 0.09; 'cest': 0.09; 'escape': 0.09; 'python': 0.11; '3):': 0.16; 'backslashes': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'hard-code': 0.16; 'literal,': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'regex,': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'have:': 0.19; 'skip:g 40': 0.19; '(the': 0.22; '>>>': 0.22; '(in': 0.22; 'header:User-Agent:1': 0.23; 'looks': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'character': 0.29; 'file': 0.32; 'raw': 0.33; 'actual': 0.34; 'could': 0.34; 'except': 0.35; 'something': 0.35; 'but': 0.35; 'should': 0.36; 'needed': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'previous': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; "you're": 0.61; 'real': 0.63; 'skip:r 40': 0.68; '2015': 0.84; 'subject:Best': 0.91 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=DZWZq5dW c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=SY9aFQKHIdAA:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=jb4FRLBzhzE_A-HHvfEA:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett@:2500 Date: Wed, 20 May 2015 00:20:30 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Best way to rewrite Popen References: <87siastsby.fsf@Equus.decebal.nl> <874mn8tm70.fsf@Equus.decebal.nl> <87zj50s4k8.fsf@Equus.decebal.nl> <87siasryuf.fsf@Equus.decebal.nl> In-Reply-To: <87siasryuf.fsf@Equus.decebal.nl> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1432077640 news.xs4all.nl 2887 [2001:888:2000:d::a6]:41128 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90902 On 2015-05-19 23:23, Cecil Westerhof wrote: > Op Tuesday 19 May 2015 23:28 CEST schreef Jon Ribbens: > >> On 2015-05-19, Cecil Westerhof wrote: >>> It looks like that this does what I want (the dot is needed so that >>> it also works with 2.7): files = sorted(os.listdir('.')) p = >>> re.compile('actions-2015-05-[0-9][0-9].sql$') current_month = [ >>> file for file in files if p.match(file) ] >> >> You could instead do (in Python 2 or 3): >> >> files = glob.glob("actions-2015-05-[0-9][0-9].sql") >> files.sort() > > Something to remember. > > But in this case I also need the previous month. So I have: > files = sorted(os.listdir('.')) > p = re.compile('actions-2015-05-[0-9][0-9].sql$') > current_month = [ file for file in files if p.match(file) ] > p = re.compile('actions-2015-04-[0-9][0-9].sql$') > previous_month = [ file for file in files if p.match(file) ] > > Of-course I will not hard-code the months in the real code. > In a regex, '.' will match any character except '\n', or any character at all if the DOTALL ('(?s)') flag in turned on. If you want to match an actual '.', you should escape it like this: r'\.'. (And if you're using backslashes in a string literal, make it a raw string literal!) p = re.compile(r'actions-2015-05-[0-9][0-9]\.sql$')