Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73308 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2014-06-16 20:06 +1000 |
| Last post | 2014-06-16 20:06 +1000 |
| 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.
Re: line to argv transformation Chris Angelico <rosuav@gmail.com> - 2014-06-16 20:06 +1000
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-06-16 20:06 +1000 |
| Subject | Re: line to argv transformation |
| Message-ID | <mailman.11080.1402913181.18130.python-list@python.org> |
On Mon, Jun 16, 2014 at 7:56 PM, Antoon Pardon
<antoon.pardon@rece.vub.ac.be> wrote:
> I am looking for an interface that takes a string as argument. The
> string is to be treated as if it is a command line and transformed into
> an argv list.
>
> "ls file" -> ['ls', 'file']
> "ls *.py" -> ['ls', 'file1.py', 'file2.py', ...]
> "ls '*.py'" -> ['ls', '*.py']
>
> Does something like this already exist? I looked around but seem to find
> only things only partially do things like this, like shlex.split.
def shell_split(cmd):
return subprocess.check_output("""python -c 'import sys;
print("\\0".join(sys.argv[1:]))' """+cmd,shell=True)[:-1].split("\0")
:)
ChrisA
Back to top | Article view | comp.lang.python
csiph-web