Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90904
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!feeds.phibee-telecom.net!news.panservice.it!feed.xsnews.nl!border01.ams.xsnews.nl!feeder01.ams.xsnews.nl!abp002.ams.xsnews.nl!frontend-F10-04.ams.news.kpn.nl |
|---|---|
| From | Cecil Westerhof <Cecil@decebal.nl> |
| Newsgroups | comp.lang.python |
| Subject | Re: Best way to rewrite Popen |
| Organization | Decebal Computing |
| 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> <mailman.155.1432077640.17265.python-list@python.org> |
| X-Face | "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR<J%a^F2lh4[N~Yz4 nSp#c+aQo1b5=?HcNEkQ7QzF<])O3X4MDL/AYjys&*mt>,v+Pti8=Vi/Z"g^?b"E |
| X-Homepage | http://www.decebal.nl/ |
| Date | Wed, 20 May 2015 02:15:14 +0200 |
| Message-ID | <87k2w4rtnx.fsf@Equus.decebal.nl> (permalink) |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
| Cancel-Lock | sha1:17CqC/KhmB00A4JG7Ky+wGGqPfo= |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| Lines | 49 |
| NNTP-Posting-Host | 81.207.62.244 |
| X-Trace | 1432081766 news.kpn.nl 20676 81.207.62.244@kpn/81.207.62.244:56090 |
| Xref | csiph.com comp.lang.python:90904 |
Show key headers only | View raw
Op Wednesday 20 May 2015 01:20 CEST schreef MRAB:
> 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$')
Oops, you are correct.
It is now:
start = database + '-'
end = r'-[0-9][0-9]\.sql$'
p = re.compile(start + current_month + end)
current_month_lst = [ file for file in files if p.match(file) ]
p = re.compile(start + previous_month + end)
previous_month_lst = [ file for file in files if p.match(file) ]
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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