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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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.