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


Groups > comp.lang.python > #92090

Re: Find in ipython3

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <random832@fastmail.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'filename': 0.07; 'filenames': 0.07; 'processing.': 0.07; 'filenames:': 0.09; 'non- ascii': 0.09; 'received:internal': 0.09; 'python': 0.11; 'dirnames,': 0.16; 'dirpath,': 0.16; 'fnmatch': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:messagingengine.com': 0.16; 'substitute': 0.16; 'wrote:': 0.16; '(or': 0.21; 'os,': 0.22; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'way?': 0.29; "skip:' 10": 0.30; 'task': 0.31; 'file': 0.34; 'needed': 0.34; 'to:addr:python-list': 0.35; 'unicode': 0.35; 'really': 0.35; 'list': 0.35; "isn't": 0.35; 'skip:o 20': 0.35; 'but': 0.36; 'there': 0.36; 'basic': 0.36; 'received:10': 0.37; 'subject:: ': 0.37; 'instead': 0.38; 'tue,': 0.38; 'received:66': 0.38; 'building': 0.38; 'skip:p 20': 0.38; 'to:addr:python.org': 0.39; 'further': 0.60; 'from:no real name:2**0': 0.61; 'header:Message- Id:1': 0.62; 'course': 0.64; 'home': 0.67; 'cecil': 0.84; 'westerhof': 0.84
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.us; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=n/NnZhmBStOGtgy+6KhAgd61QBQ=; b=KEQ1ub e2PPKUeHldFvUkzUzl0fEjmW1Pndqa0WQs/HIworANWnYGLdG9YaginViTANLksf /nGT1jX2v/XSosKz3zy5Uaj4tB8Ji41sTSNQfZI+aYjuGBAj8OL5Tvq7ZybjHft0 kePU9iyIoR85UOOQ/+co/K6gCnqRkSpkaf6DI=
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=n/NnZhmBStOGtgy +6KhAgd61QBQ=; b=oERJ46UCLal41JAs51+/DcKLs8uh6xfLiHhQ7NU3vHJC0tW GqJWmpwxoOkWP4Aoh4f3v1j5KVCLGVknUloO0jS84l/JDoQQiTddgSiVyvdBOXmB evtdbejxqgq41sqX+PjLGrPDrRP2dl3i57NXjQTPYmAI/vC/pHJ/G18RUvdU=
X-Sasl-Enc 22bLXJRiiLL2lndaloM4RJRxWoRydrfX3DGbhDeEPKEF 1433448832
From random832@fastmail.us
To python-list@python.org
MIME-Version 1.0
Content-Transfer-Encoding 7bit
Content-Type text/plain
X-Mailer MessagingEngine.com Webmail Interface - ajax-96e2a13b
In-Reply-To <87y4k2hyvf.fsf@Equus.decebal.nl>
References <87y4k2hyvf.fsf@Equus.decebal.nl>
Subject Re: Find in ipython3
Date Thu, 04 Jun 2015 16:13:52 -0400
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.177.1433448836.13271.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1433448836 news.xs4all.nl 2907 [2001:888:2000:d::a6]:49314
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:92090

Show key headers only | View raw


On Tue, Jun 2, 2015, at 12:13, Cecil Westerhof wrote:
> I am thinking about using ipython3 instead of bash. When I want to
> find a file I can do the following:
>     !find ~ -iname '*python*.pdf'
> but is there a python way?

Python really isn't a good substitute for a shell, but the normal python
way to do this task is:

import os, os.path, fnmatch

home = os.path.expanduser('~')  # only needed since you used ~
for dirpath, dirnames, filenames in os.walk(home):
    print(dirpath)
    for filename in filenames:
        if(fnmatch.fnmatch(filename.lower(), '*python*.pdf')):
            print(os.path.join(dirpath, filename))

Note that if you have filenames with invalid unicode characters (or any
non-ASCII characters at all on Windows) you may have to do additional
processing to the filename before printing it. And of course instead of
printing it you may want to store the filenames in a list for further
processing. But these are the basic building blocks.

I don't use ipython, so I don't know what it provides if anything to
make any of this easier.

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


Thread

Find in ipython3 Cecil Westerhof <Cecil@decebal.nl> - 2015-06-02 18:13 +0200
  Re: Find in ipython3 Cameron Simpson <cs@zip.com.au> - 2015-06-04 12:54 +1000
    Re: Find in ipython3 Cecil Westerhof <Cecil@decebal.nl> - 2015-06-04 07:09 +0200
      Re: Find in ipython3 Cameron Simpson <cs@zip.com.au> - 2015-06-04 15:43 +1000
      Re: Find in ipython3 Grant Edwards <invalid@invalid.invalid> - 2015-06-04 14:27 +0000
        Re: Find in ipython3 Cecil Westerhof <Cecil@decebal.nl> - 2015-06-04 17:12 +0200
          Re: Find in ipython3 Michael Torrie <torriem@gmail.com> - 2015-06-04 13:11 -0600
  Re: Find in ipython3 Michael Torrie <torriem@gmail.com> - 2015-06-04 13:09 -0600
  Re: Find in ipython3 Tim Chase <python.list@tim.thechases.com> - 2015-06-04 14:17 -0500
  Re: Find in ipython3 random832@fastmail.us - 2015-06-04 16:13 -0400
    Re: Find in ipython3 Cecil Westerhof <Cecil@decebal.nl> - 2015-06-05 09:17 +0200
      Re: Find in ipython3 Cecil Westerhof <Cecil@decebal.nl> - 2015-06-06 11:57 +0200
        Re: Find in ipython3 Laura Creighton <lac@openend.se> - 2015-06-06 13:07 +0200
          Re: Find in ipython3 Cecil Westerhof <Cecil@decebal.nl> - 2015-06-07 08:20 +0200
            Re: Find in ipython3 Cameron Simpson <cs@zip.com.au> - 2015-06-07 17:38 +1000
            Re: Find in ipython3 Laura Creighton <lac@openend.se> - 2015-06-07 11:33 +0200
              Re: Find in ipython3 Steven D'Aprano <steve@pearwood.info> - 2015-06-07 23:16 +1000
            Re: Find in ipython3 Peter Otten <__peter__@web.de> - 2015-06-07 12:27 +0200
            Re: Find in ipython3 Laura Creighton <lac@openend.se> - 2015-06-07 15:01 +0200
            Re: Find in ipython3 Chris Angelico <rosuav@gmail.com> - 2015-06-07 22:13 +1000

csiph-web