Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.wiretrip.org!newsfeed.xs4all.nl!newsfeed5.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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'sys': 0.05; 'importerror:': 0.07; 'python': 0.08; '__name__': 0.09; 'am,': 0.13; 'wrote:': 0.15; '\'%s\'\\n"': 0.16; "'\\n')": 0.16; "'__main__':": 0.16; 'billy': 0.16; '\xc2\xa0if': 0.16; 'cc:addr :python-list': 0.16; 'aug': 0.19; 'cheers,': 0.19; 'wrote': 0.21; 'cc:2**0': 0.21; 'cc:no real name:2**0': 0.22; 'header:In-Reply- To:1': 0.22; 'hey': 0.26; 'skip:_ 20': 0.28; 'thu,': 0.28; 'message-id:@mail.gmail.com': 0.28; 'import': 0.29; 'script': 0.29; 'cc:addr:python.org': 0.30; 'module': 0.30; 'skip:\xc2 20': 0.30; 'seem': 0.31; 'chris': 0.32; 'anyone': 0.33; 'skip:# 10': 0.34; "can't": 0.34; 'file': 0.36; 'anything': 0.37; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85.161': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.38; '8bit%:8': 0.38; 'think': 0.38; 'received:209': 0.40; 'your': 0.60; 'skip:\xc2 10': 0.74; 'sender:addr:chris': 0.84; 'url:rebertia': 0.84; 'to:none': 0.93; 'from.': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:cc:content-type :content-transfer-encoding; bh=a9QH4aToDh8K97ekvjxm6qvVt7LGOrwO7TNG8M/SROE=; b=CLyT8fcRtCs/xJYoGHYntYcYKTlrqHv3gqX+kRRrMJtygbwa5HK3l6jiyGk16w1js+ XTH7CgwPL2VcPz3CFle71celw3BIcEHYEtiHeX4utP4YMT9vuESdEGc0wPcKVu0DVWFO UFMQbm9DDWPk4oiynXDA/j2b23BSv0ZOAdYlI= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: References: Date: Thu, 4 Aug 2011 10:22:43 -0700 X-Google-Sender-Auth: csPLiNZAO4h_-xQeppUYbmGByQg Subject: Re: PyWhich From: Chris Rebert Cc: python-list@python.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312478566 news.xs4all.nl 23850 [2001:888:2000:d::a6]:45592 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10865 On Thu, Aug 4, 2011 at 5:43 AM, Billy Mays <81282ed9a88799d21e77957df2d84bd6514d9af6@myhashismyemail.com> wrote: > Hey c.l.p., > > I wrote a little python script that finds the file that a python module c= ame > from. =C2=A0Does anyone see anything wrong with this script? > > > #!/usr/bin/python > > import sys > if __name__ =3D=3D '__main__': > =C2=A0 =C2=A0if len(sys.argv) > 1: > =C2=A0 =C2=A0 =C2=A0 =C2=A0try: > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0m =3D __import__(sys.argv[1]) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sys.stdout.write(m.__file__ + '\= n') > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sys.stdout.flush() > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sys.exit(0) > =C2=A0 =C2=A0 =C2=A0 =C2=A0except ImportError: > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sys.stderr.write("No such module= '%s'\n" % sys.argv[1]) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sys.stderr.flush() > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sys.exit(1) > =C2=A0 =C2=A0else: > =C2=A0 =C2=A0 =C2=A0 =C2=A0sys.stderr.write("Usage: pywhich \n") > =C2=A0 =C2=A0 =C2=A0 =C2=A0sys.stderr.flush() > =C2=A0 =C2=A0 =C2=A0 =C2=A0sys.exit(0) Nothing wrong per se, but the flush()es seem unnecessary, and why do stdout.write() when you can just print()? Cheers, Chris -- I can't not think of the pitchman when I read your posts... http://rebertia.com