On Thu, Aug 4, 2011 at 10:22 AM, Chris Rebert <c...@rebertia.com> wrote:

>
> > #!/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()?
>

The flushes are unnecessary, but sys.stdout.write has an advantage over
print: sys.stdout.write works pretty much the same in both 2.x and 3.x;
print doesn't.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to