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


Groups > comp.lang.python > #51225

Re: Critic my module

From Alain Ketterlin <alain@dpt-info.u-strasbg.fr>
Newsgroups comp.lang.python
Subject Re: Critic my module
Date 2013-07-25 16:09 +0200
Organization Universites Paris VI/Paris VII - France
Message-ID <87y58u20l0.fsf@dpt-info.u-strasbg.fr> (permalink)
References <mailman.5092.1374758683.3114.python-list@python.org>

Show all headers | View raw


Devyn Collier Johnson <devyncjohnson@gmail.com> writes:

>    I made a Python3 module that allows users to use certain Linux
> shell commands from Python3 more easily than using os.system(),
> subprocess.Popen(), or subprocess.getoutput(). This module (once
> placed with the other modules) can be used like this

Good, but I doubt it's really useful: I think nobody is going to add a
dependency on your module for, basically, one-line wrappers...

Here are a few comments:

> def ls():
> 	version = '0.3'
> 	print(subprocess.getoutput('ls'))

version is local here, so basically your first statement is useless
(search for "global" in python's language ref).

> def uname():
> 	version = '0.3'
> 	print(platform.uname())

I once learned: "never print anything in a library function". This is a
bad thing to do, for a variety of reasons. For instance, stdout may be
redirected during this call...

> def man(x):
> 	version = '0.3'
> 	print(subprocess.getoutput('man' + x))

getoutput is (essentially) Popen(...,shell=True), and the doc says:

"the use of shell=True is strongly discouraged in cases where the
command string is constructed from external input"

(for very good reasons)

> def clear_bash_history():
> 	version = '0.3'
> 	print(subprocess.getoutput('history -c'))

Who told you subprocess will use bash? Again, the doc:

"On Unix with shell=True, the shell defaults to /bin/sh."

All your uses of bash-isms may break (esp. "!!")

> def firefox():
> 	version = '0.3'
> 	print(subprocess.Popen('(firefox &)'))

See section "Replacing the os.spawn family" in... the doc.

> def go_back():
> 	version = '0.3'
> 	print(subprocess.Popen('cd !!:1'))

Hopeless. Have you tried this?

> def reboot():
> 	version = '0.3'
> 	print(subprocess.Popen('shutdown -r now'))

What do you expect this to print? I mean, after shutdown/reboot.

> version = '0.6b'

So, what's the version? 0.3 or 0.6b

(btw, are you sure this "version" is the same as the one you use in all
functions?).

-- Alain.

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


Thread

Critic my module Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-25 09:24 -0400
  Re: Critic my module Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2013-07-25 16:09 +0200
    Re: Critic my module Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-26 06:59 -0400
      Re: Critic my module Alister <alister.ware@ntlworld.com> - 2013-07-26 15:08 +0000
        Re: Critic my module Joshua Landau <joshua@landau.ws> - 2013-07-26 18:24 +0100
  Re: Critic my module Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-27 02:48 +0000
    Re: Critic my module Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-27 08:56 -0400
      Re: Critic my module Alister <alister.ware@ntlworld.com> - 2013-07-27 16:32 +0000
        Re: Critic my module Dave Angel <davea@davea.name> - 2013-07-27 12:58 -0400
    Re: Critic my module Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-27 09:19 -0400
    Re: Critic my module Dave Angel <davea@davea.name> - 2013-07-27 09:35 -0400
    Re: Critic my module Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-07-27 15:36 +0200
    Re: Critic my module Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-27 09:44 -0400
    Re: Critic my module Chris Angelico <rosuav@gmail.com> - 2013-07-27 14:37 +0100
    Re: Critic my module Dave Angel <davea@davea.name> - 2013-07-27 10:33 -0400
    Re: Critic my module Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-27 10:53 -0400
    Re: Critic my module Chris Angelico <rosuav@gmail.com> - 2013-07-27 16:15 +0100

csiph-web