Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10865
| References | <j1e45l$jtg$1@speranza.aioe.org> |
|---|---|
| Date | 2011-08-04 10:22 -0700 |
| Subject | Re: PyWhich |
| From | Chris Rebert <clp2@rebertia.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1895.1312478566.1164.python-list@python.org> (permalink) |
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 came
> from. Does anyone see anything wrong with this script?
>
>
> #!/usr/bin/python
>
> import sys
> if __name__ == '__main__':
> if len(sys.argv) > 1:
> try:
> m = __import__(sys.argv[1])
> sys.stdout.write(m.__file__ + '\n')
> sys.stdout.flush()
> sys.exit(0)
> except ImportError:
> sys.stderr.write("No such module '%s'\n" % sys.argv[1])
> sys.stderr.flush()
> sys.exit(1)
> else:
> sys.stderr.write("Usage: pywhich <module>\n")
> sys.stderr.flush()
> sys.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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
PyWhich Billy Mays <81282ed9a88799d21e77957df2d84bd6514d9af6@myhashismyemail.com> - 2011-08-04 08:43 -0400
Re: PyWhich Chris Rebert <clp2@rebertia.com> - 2011-08-04 10:22 -0700
Re: PyWhich Tim Chase <python.list@tim.thechases.com> - 2011-08-04 13:24 -0500
Re: PyWhich Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-05 10:34 +1000
Re: PyWhich Tim Chase <python.list@tim.thechases.com> - 2011-08-04 20:04 -0500
Re: PyWhich Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-05 23:51 +1000
Re: PyWhich Tim Golden <mail@timgolden.me.uk> - 2011-08-05 15:03 +0100
Re: PyWhich John Gordon <gordon@panix.com> - 2011-08-05 14:33 +0000
Re: PyWhich Chris Angelico <rosuav@gmail.com> - 2011-08-05 03:03 +0100
Re: PyWhich Billy Mays <81282ed9a88799d21e77957df2d84bd6514d9af6@myhashismyemail.com> - 2011-08-05 10:43 -0400
Re: PyWhich Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-06 00:56 +1000
Re: PyWhich Web Dreamer <webdreamer@nospam.fr> - 2011-08-05 16:34 +0200
csiph-web