Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed1.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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; 'everyone!': 0.07; 'python3': 0.07; 'collier': 0.09; 'launchpad': 0.09; 'parsing': 0.09; 'performs': 0.09; 'python': 0.11; 'systems.': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'stdout': 0.16; 'superfluous': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'help.': 0.21; '>>>': 0.22; 'shell': 0.22; 'print': 0.22; '31,': 0.24; 'skip': 0.24; 'subject:Code': 0.24; 'script': 0.25; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'chris': 0.29; 'am,': 0.29; 'unix': 0.29; 'nature': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'lines': 0.31; 'that.': 0.31; 'prints': 0.31; 'file': 0.32; 'text': 0.33; 'linux': 0.33; 'everyone': 0.33; 'maybe': 0.34; 'could': 0.34; "can't": 0.35; 'johnson': 0.35; 'one,': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'licensed': 0.36; 'done': 0.36; 'useful': 0.36; 'two': 0.37; 'easily': 0.37; 'process,': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'read': 0.60; 'truly': 0.60; 'skip:o 30': 0.61; 'simply': 0.61; 'soon': 0.63; '30,': 0.65; 'laptop': 0.65; 'jul': 0.74; 'account.': 0.80; 'promptly': 0.84; 'subject:Laptop': 0.84; 'subject:State': 0.84; 'capture': 0.91; 'contents.': 0.91; 'shell,': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=iOEOgublUW1j1K5OzgPVnEeOHKBf888yL1F1IRhLOxw=; b=Y4i99oB0ukLqRVmZwbuAV6svHvMvbZr2Lf5NYKsxhyUcNLfA1alYM8GCFLWPXou2gu roan0G1eKG/Yt4nrBKdvui7Zl1pQmtrSYEknUiozM8Md5A3FoO7y+DVeAdQHJ7FlJG6f JOTxvyh3mu+S68PjTfAyeUeZ1u1XHTsXNQE+hdGys3hLWpLzkdDWyG6EZcqn4fsZy38t 7LvMhEIS5PYS+fOt0C74/VS70UJxAdxFhK2cMgFv8kX5YuQnkrVxXqoi722gHssyLm7y QMCCoxZjFeJ/ng8uzgCLx7scAOzZI0iOro4vQTDAZnW8bMlJzclZKpjg6xliZfsdwsBw 4tFA== MIME-Version: 1.0 X-Received: by 10.52.178.194 with SMTP id da2mr13097560vdc.28.1375254886065; Wed, 31 Jul 2013 00:14:46 -0700 (PDT) In-Reply-To: <51F87EE1.50206@Gmail.com> References: <51F7C861.3060208@Gmail.com> <51F87EE1.50206@Gmail.com> Date: Wed, 31 Jul 2013 08:14:46 +0100 Subject: Re: Share Code: Laptop Lid State From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375254889 news.xs4all.nl 15869 [2001:888:2000:d::a6]:33735 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51626 On Wed, Jul 31, 2013 at 4:05 AM, Devyn Collier Johnson wrote: > > On 07/30/2013 12:00 PM, Chris Angelico wrote: >> >> On Tue, Jul 30, 2013 at 3:06 PM, Devyn Collier Johnson >> wrote: >>> >>> Aloha everyone! >>> >>> I attached a script that I thought I could share with everyone for >>> your >>> help. This Python3 script only works on Unix systems. It prints the >>> current >>> state of the lid. This can be used to make a script that performs some >>> action when the lid is closed or open. The script is licensed under >>> LGPLv3 >>> and I will soon upload it to my Launchpad account. Enjoy! >> >> There's... no Python code in that. Why not simply >> open("/proc/acpi/button/lid/LID/state") and read from it, instead of >> using cat and awk? >> >> ChrisA > > The script returns either "open" or "close" instead of printing the whole > file contents. I thought some people would find it useful (^_^;). Not having a Linux laptop handy I can't test it, but my point is that text parsing of that nature can be done directly by Python. You can snip out the "open" or "close" easily with one, maybe two lines of code at the most, and that without dropping to a shell, a completely superfluous 'cat' process, and awk. You then capture the STDOUT of that and promptly print it to your own STDOUT. Why not either do it truly in Python, or do it directly in a shell script and skip the Python interpreter? ChrisA