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


Groups > comp.lang.python > #72297

Re: Multi-line commands with 'python -c'

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
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; 'python,': 0.02; 'operator': 0.03; 'python3': 0.07; 'friday,': 0.09; 'modulo': 0.09; 'operator,': 0.09; 'statements': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; 'question.': 0.14; "','": 0.16; "';'": 0.16; "'from": 0.16; 'at.': 0.16; 'command.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'newlines': 0.16; 'notation': 0.16; 'semicolon': 0.16; 'ternary': 0.16; 'url:debian': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; "python's": 0.19; 'version.': 0.19; 'import': 0.22; 'putting': 0.22; 'rules': 0.22; 'cc:addr:python.org': 0.22; 'certainly': 0.24; 'convenient': 0.24; 'cc:2**0': 0.24; 'asking': 0.27; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'chris': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'lines': 0.31; 'url:05': 0.31; 'fri,': 0.33; 'not.': 0.33; 'programmers': 0.33; 'subject:with': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'opposed': 0.36; 'url:org': 0.36; 'two': 0.37; 'list': 0.37; 'pm,': 0.38; 'most': 0.60; "you're": 0.61; 'more': 0.64; '30,': 0.65; 'dont': 0.67; '100': 0.79; 'crafted': 0.84; 'line!': 0.84; 'saying:': 0.84; 'subject:commands': 0.84; 'url:2014': 0.84; 'to:none': 0.92
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:cc :content-type; bh=/wPUkC28aIgoJrRJ8yTPwt82Jbr2Y0cOUmyxyTAmAjM=; b=DOvaKzvHWGcAHP2cp8KV7zO5ii/tKNXTUnIumfiru5wkZzGYfKLBVcgQclKDBCpw3i jbJfSXx7oAqXfYuMKsOsrNzBF4jZxwalCy5k7+ZuAvlTiLdlzoXG0CXk1VHmPdFzh+lm L8CDDw3VEvjREPQCOu0i/BwSSD63tQpliCKCAhay2K0k12N3nljcZSB1sSGiNjk+mNgw YQH2zRfey7H17nb4HnP93vKlbQ+du8AER4mkvCI6nUedApEeOUREUXhmQCZKAP3QpPQT +gpNvQ+dZaBbuFn+ZHSmB8aqZ18kgYdxPsUz9XhgwWzog7yahO57X84jdkFkpWZtSx6q 2uhQ==
MIME-Version 1.0
X-Received by 10.52.167.132 with SMTP id zo4mr217497vdb.97.1401454698170; Fri, 30 May 2014 05:58:18 -0700 (PDT)
In-Reply-To <a5dd8a43-58e2-4fb7-b2c2-c62601bce3d5@googlegroups.com>
References <mailman.10468.1401411146.18130.python-list@python.org> <25135194-b9cb-4942-bead-c1bdf72923ee@googlegroups.com> <mailman.10478.1401434433.18130.python-list@python.org> <a5dd8a43-58e2-4fb7-b2c2-c62601bce3d5@googlegroups.com>
Date Fri, 30 May 2014 22:58:18 +1000
Subject Re: Multi-line commands with 'python -c'
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.10484.1401454700.18130.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1401454700 news.xs4all.nl 2854 [2001:888:2000:d::a6]:54493
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72297

Show key headers only | View raw


On Fri, May 30, 2014 at 10:47 PM, Rustom Mody <rustompmody@gmail.com> wrote:
> On Friday, May 30, 2014 12:50:31 PM UTC+5:30, Chris Angelico wrote:
>> On Fri, May 30, 2014 at 4:04 PM, Rustom Mody wrote:
>> > I thought when one signs up for python one has to sign an affidavit
>> > saying:
>> > "I shall not write one-liners\n" * 100
>
>> Certainly not. I write all my list comps on one line!
>
>> *ducking for cover*
>
> Heres a more vile misuse of python3's print-as-function + list-comp-as-for:
>
> python3 -c 'from os import walk; [print(r) for r, d, f in walk(".") if len(d+f) == 1]'
>
> Well if C programmers can use ',' as one-line ';' and '?:' as one-line if
> why not python also?
>
> [To noobs who are reading: Dont do this!]

I actually crafted the exact same vile misuse, prior to asking the question.

https://lists.debian.org/debian-user/2014/05/msg02019.html

Modulo trivialities like whitespace and the from-import, it's exactly
the same as your version.

Incidentally, C's ?: operator maps to Python's ternary if/else
operator, which most definitely is valid in a one-liner. So it's just
the semicolon that you're looking at. In C, you can combine any two
statements onto one line; in Python, certain statements may not follow
a semicolon. So it's not really ; and ?: that are the point here, but
that Python, with its stricter rules about newlines (as opposed to
"any whitespace"), doesn't seem to have a convenient notation for
putting multiple lines into a -c command.

ChrisA

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


Thread

Multi-line commands with 'python -c' Chris Angelico <rosuav@gmail.com> - 2014-05-30 10:52 +1000
  Re: Multi-line commands with 'python -c' Rustom Mody <rustompmody@gmail.com> - 2014-05-29 23:04 -0700
    Re: Multi-line commands with 'python -c' Rustom Mody <rustompmody@gmail.com> - 2014-05-29 23:45 -0700
      Re: Multi-line commands with 'python -c' Rustom Mody <rustompmody@gmail.com> - 2014-05-29 23:54 -0700
        Re: Multi-line commands with 'python -c' Peter Otten <__peter__@web.de> - 2014-05-30 09:33 +0200
      Re: Multi-line commands with 'python -c' Terry Reedy <tjreedy@udel.edu> - 2014-05-30 11:29 -0400
    Re: Multi-line commands with 'python -c' Chris Angelico <rosuav@gmail.com> - 2014-05-30 17:20 +1000
      Re: Multi-line commands with 'python -c' Rustom Mody <rustompmody@gmail.com> - 2014-05-30 05:47 -0700
        Re: Multi-line commands with 'python -c' Chris Angelico <rosuav@gmail.com> - 2014-05-30 22:58 +1000
  Re: Multi-line commands with 'python -c' Duncan Booth <duncan.booth@invalid.invalid> - 2014-05-30 21:11 +0000
    Re: Multi-line commands with 'python -c' Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-05-30 14:42 -0700
    Re: Multi-line commands with 'python -c' Chris Angelico <rosuav@gmail.com> - 2014-05-31 07:47 +1000
      Re: Multi-line commands with 'python -c' Duncan Booth <duncan.booth@invalid.invalid> - 2014-05-31 16:41 +0000
        Re: Multi-line commands with 'python -c' Peter Otten <__peter__@web.de> - 2014-05-31 19:11 +0200
          Re: Multi-line commands with 'python -c' Duncan Booth <duncan.booth@invalid.invalid> - 2014-06-01 20:43 +0000

csiph-web