Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73310
| Path | csiph.com!usenet.pasdenom.info!aioe.org!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; '16,': 0.03; 'assuming': 0.09; 'prefix': 0.09; 'subject:skip:t 10': 0.09; 'api': 0.11; 'cc:addr:python-list': 0.11; 'def': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'operation,': 0.16; 'string:': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'split': 0.19; 'cc:addr:python.org': 0.22; 'error': 0.23; 'byte': 0.24; 'case.': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'skip:" 30': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'skip:p 30': 0.29; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; '"",': 0.31; '>>>>': 0.31; 'idea,': 0.31; 'file': 0.32; '(most': 0.33; 'skip:s 30': 0.35; 'received:google.com': 0.35; 'list': 0.37; 'pm,': 0.38; 'recent': 0.39; 'free': 0.61; 'back': 0.62; "you'll": 0.62; 'incorporate': 0.68; "it'd": 0.84; 'pardon': 0.84; 'wish.': 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=9neyJi9Zedw5QnViPKErQE3CebdM2WituQaLsGiHCkM=; b=AKwg0rSkMgnc1DzX136Sin8X4yJEXG9hCBEZm5SOAJ0wajeHkPBQ/w5sIjqVdDkmf8 bJhkhG6dYOUXJOqThQquq7qfnrz3EBjF/rcYHLBbc5682xQ+FvahUZ0zh1ebBYA3ZNzb R/XOQ9k6IFmrStT6OmvSnGN6sY6blvqaIcXcZ5SawkwQGy0sKRHeeTJjSQso/eANOAjl AUPFD+m107EofWcuDXYTlGHUrttmpNiCxBdY5e+OFdl+lmIhaHt+koPSnwJDEx5V+LZK MS5vWN3nNCM/Y9Q7fzuJinwvsdcT/F2o4H2Ctxtz6Kbul9xi/67apefjgP0eOWNSM5So A89g== |
| MIME-Version | 1.0 |
| X-Received | by 10.221.51.77 with SMTP id vh13mr10345vcb.41.1402915281130; Mon, 16 Jun 2014 03:41:21 -0700 (PDT) |
| In-Reply-To | <539EC5EF.7040205@rece.vub.ac.be> |
| References | <539EBF61.4050106@rece.vub.ac.be> <CAPTjJmqd74v013WwG2QrZP2y9N+gMk0TK5xT5-yy3=8gOuAs4g@mail.gmail.com> <539EC5EF.7040205@rece.vub.ac.be> |
| Date | Mon, 16 Jun 2014 20:41:21 +1000 |
| Subject | Re: line to argv transformation |
| 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.11082.1402915284.18130.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1402915284 news.xs4all.nl 2925 [2001:888:2000:d::a6]:52757 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:73310 |
Show key headers only | View raw
On Mon, Jun 16, 2014 at 8:24 PM, Antoon Pardon
<antoon.pardon@rece.vub.ac.be> wrote:
> On 16-06-14 12:06, Chris Angelico wrote:
>
>> def shell_split(cmd):
>> return subprocess.check_output("""python -c 'import sys;
>> print("\\0".join(sys.argv[1:]))' """+cmd,shell=True)[:-1].split("\0")
>
> Nice idea, unfortunatly it doesn't work in python3.3
>
>>>> shell_split("ls *.py")
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "<stdin>", line 3, in shell_split
> TypeError: Type str doesn't support the buffer API
>>>>
Oops! I made the cardinal error of trying in one and assuming it'd
work in both. Just needs a b prefix on the split string:
def shell_split(cmd):
return subprocess.check_output("""python -c 'import sys;
print("\\0".join(sys.argv[1:]))' """+cmd,shell=True)[:-1].split(b"\0")
You'll get back a list of byte strings, in any case. Feel free to pass
them through a decode operation, or to incorporate a .decode() into
the above stream, as you wish.
ChrisA
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: line to argv transformation Chris Angelico <rosuav@gmail.com> - 2014-06-16 20:41 +1000
Re: line to argv transformation Marko Rauhamaa <marko@pacujo.net> - 2014-06-16 13:59 +0300
Re: line to argv transformation Chris Angelico <rosuav@gmail.com> - 2014-06-16 21:25 +1000
csiph-web