Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90902

Re: Best way to rewrite Popen

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 <python@mrabarnett.plus.com>
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 <python@mrabarnett.plus.com>
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> <slrnmlmt6n.864.jon+usenet@frosty.unequivocal.co.uk> <874mn8tm70.fsf@Equus.decebal.nl> <87zj50s4k8.fsf@Equus.decebal.nl> <slrnmlnaqp.864.jon+usenet@frosty.unequivocal.co.uk> <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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.155.1432077640.17265.python-list@python.org> (permalink)
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

Show key headers only | View raw


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 <Cecil@decebal.nl> 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$')

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Best way to rewrite Popen Cecil Westerhof <Cecil@decebal.nl> - 2015-05-19 19:01 +0200
  Re: Best way to rewrite Popen Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-05-19 17:36 +0000
    Re: Best way to rewrite Popen Cecil Westerhof <Cecil@decebal.nl> - 2015-05-19 21:13 +0200
      Re: Best way to rewrite Popen Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-05-19 20:14 +0000
      Re: Best way to rewrite Popen Cecil Westerhof <Cecil@decebal.nl> - 2015-05-19 22:19 +0200
        Re: Best way to rewrite Popen Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-05-19 21:28 +0000
          Re: Best way to rewrite Popen Cecil Westerhof <Cecil@decebal.nl> - 2015-05-20 00:23 +0200
            Re: Best way to rewrite Popen MRAB <python@mrabarnett.plus.com> - 2015-05-20 00:20 +0100
              Re: Best way to rewrite Popen Cecil Westerhof <Cecil@decebal.nl> - 2015-05-20 02:15 +0200
  Re: Best way to rewrite Popen Jonas Wielicki <jonas@wielicki.name> - 2015-05-19 19:43 +0200
  Re: Best way to rewrite Popen Chris Angelico <rosuav@gmail.com> - 2015-05-20 03:47 +1000
  Re: Best way to rewrite Popen Zachary Ware <zachary.ware+pylist@gmail.com> - 2015-05-19 12:55 -0500
  Re: Best way to rewrite Popen Chris Angelico <rosuav@gmail.com> - 2015-05-20 04:13 +1000
  Re: Best way to rewrite Popen Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-20 03:23 +0200

csiph-web