Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.05; 'defaults': 0.07; 'python3': 0.07; 'redirected': 0.07; 'string': 0.09; 'alain': 0.09; 'collier': 0.09; 'dependency': 0.09; 'newline': 0.09; 'subject:module': 0.09; 'useless': 0.09; 'python': 0.11; 'def': 0.12; '"global"': 0.16; '0.3': 0.16; 'command,': 0.16; 'comments:': 0.16; 'doc:': 0.16; 'for,': 0.16; 'in...': 0.16; 'mean,': 0.16; 'stdout': 0.16; 'version?': 0.16; 'do,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'library': 0.18; 'module': 0.19; 'basically': 0.19; "python's": 0.19; 'command': 0.22; 'shell': 0.22; 'print': 0.22; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'instance,': 0.24; '(for': 0.26; 'certain': 0.27; 'header:In- Reply-To:1': 0.27; 'tried': 0.27; 'point': 0.28; 'function': 0.29; 'external': 0.29; 'skip:p 30': 0.29; 'am,': 0.29; 'unix': 0.29; 'statement': 0.30; 'strongly': 0.30; 'received:10.0.0': 0.31; 'that.': 0.31; 'catching': 0.31; 'doc': 0.31; 'quotes': 0.31; 'writes:': 0.31; 'allows': 0.31; 'linux': 0.33; 'cases': 0.33; '"the': 0.34; 'could': 0.34; 'johnson': 0.35; 'no,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'version': 0.36; 'really': 0.36; 'doubt': 0.36; 'module.': 0.36; 'received:10.0': 0.36; 'so,': 0.37; 'received:10': 0.37; 'easily': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'anything': 0.39; 'expect': 0.39; 'bad': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'users': 0.40; 'how': 0.40; 'commands': 0.60; 'number,': 0.60; 'break': 0.61; 'increased': 0.61; 'first': 0.61; 'happen': 0.63; 'more': 0.64; 'here': 0.66; 'nobody': 0.68; 'overall': 0.69; 'increase': 0.74; 'commands.': 0.84; 'good,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=/6Oa6GT06stOQx+fHPE70sWg7PCNDSm1xjLeZEu+iQ8=; b=Cn6TuQX9EAFtxhbw4Ar/uVkgdfR4XBHwBDH3HDA7X5a+ZqeqPxAgnDzXB/Q602h+mr Tz0aGTzS2eGbPmwLDdJd/QPyHIpWm4lqUg//mw7Y1SkUNLrC30m6ALV3a+Cq4gB8jJdF AfhmTPZ7FuBjY0N4HkEpmroMt3V/3HbrBgofiTLigmRnOGnXA4g/C3itOWGNP6k+S169 TRJRRlcXXkcGWtbdX4xB+o2XU2UMIRSfDNpeq1bRRGVBzRWUQ+WWXUkRpMIdAOcVOqCu 8Os+rkD150NJnk4QaU6F6Fh/ixbnLmra4jIt0LzpnBe6KFBcEe7OVwhq7IyEVGVY+iyM kMZQ== X-Received: by 10.60.133.14 with SMTP id oy14mr47142857oeb.84.1374836358445; Fri, 26 Jul 2013 03:59:18 -0700 (PDT) Date: Fri, 26 Jul 2013 06:59:15 -0400 From: Devyn Collier Johnson User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 MIME-Version: 1.0 To: Python Mailing List Subject: Re: Critic my module References: <87y58u20l0.fsf@dpt-info.u-strasbg.fr> In-Reply-To: <87y58u20l0.fsf@dpt-info.u-strasbg.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 92 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1374836361 news.xs4all.nl 15935 [2001:888:2000:d::a6]:58800 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51297 On 07/25/2013 10:09 AM, Alain Ketterlin wrote: > Devyn Collier Johnson 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