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


Groups > comp.lang.python > #51626 > unrolled thread

Re: Share Code: Laptop Lid State

Started byChris Angelico <rosuav@gmail.com>
First post2013-07-31 08:14 +0100
Last post2013-07-31 08:14 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Share Code: Laptop Lid State Chris Angelico <rosuav@gmail.com> - 2013-07-31 08:14 +0100

#51626 — Re: Share Code: Laptop Lid State

FromChris Angelico <rosuav@gmail.com>
Date2013-07-31 08:14 +0100
SubjectRe: Share Code: Laptop Lid State
Message-ID<mailman.5354.1375254889.3114.python-list@python.org>
On Wed, Jul 31, 2013 at 4:05 AM, Devyn Collier Johnson
<devyncjohnson@gmail.com> wrote:
>
> On 07/30/2013 12:00 PM, Chris Angelico wrote:
>>
>> On Tue, Jul 30, 2013 at 3:06 PM, Devyn Collier Johnson
>> <devyncjohnson@gmail.com> 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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web