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


Groups > comp.lang.python > #51297

Re: Critic my module

Date 2013-07-26 06:59 -0400
From Devyn Collier Johnson <devyncjohnson@gmail.com>
Subject Re: Critic my module
References <mailman.5092.1374758683.3114.python-list@python.org> <87y58u20l0.fsf@dpt-info.u-strasbg.fr>
Newsgroups comp.lang.python
Message-ID <mailman.5144.1374836361.3114.python-list@python.org> (permalink)

Show all headers | View raw


On 07/25/2013 10:09 AM, Alain Ketterlin wrote:
> 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.

The version in each function is the version of that function if users 
want to know what version they are using. The last version is for the 
whole module. The module overall is version 0.6b. The module started 
with a few functions and as I increased the number of functions, I 
increased the module version number. It is a coincidence that all of the 
modules happen to have the same version number. I increase the version 
number after I work on a function. I cannot remember the command to 
print a module's/function's version number, but with that command, you 
could see the version of a particular function or module. No, I have not 
tried go_back(), thank you for catching that.

The main point of this is for shell users that are using Python and do 
not know some of the Python commands. This module would make Python more 
like a Linux shell. For instance, a shell user would type boash.uname() 
because they may not know they can type "import platform; platform.uname()".

I know that printing is not really the best of ideas, but how else can I 
make the output be displayed without quotes or newline marks?

Thank you very much Alain Ketterlin for your feedback!

Mahalo,

DCJ

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