[issue40568] Modify -c command-line option to accept multiple inputs

2020-05-23 Thread Florian Dahlitz


Change by Florian Dahlitz :


--
nosy:  -DahlitzFlorian

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40568] Modify -c command-line option to accept multiple inputs

2020-05-22 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

It would be breaking change.

In addition to multiline strings you can use \n with $' on Posix:

python -c $'with open("somefile.txt") as f:\n  s = f.read()\n  print(len(s))'

Maybe there is similar feature on Windows, but in any case the command line 
interface on Windows is far from user friendly.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40568] Modify -c command-line option to accept multiple inputs

2020-05-22 Thread Florian Dahlitz


Change by Florian Dahlitz :


--
nosy: +DahlitzFlorian

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40568] Modify -c command-line option to accept multiple inputs

2020-05-08 Thread Zachary Ware


Zachary Ware  added the comment:

This can be accomplished already by just including newlines in the string:

$ cat multiline_python_bash_script.sh 
#!/bin/bash

python3 -c '
from math import *
print(e**(1j * pi))
import sys
print(sys.argv)'

echo "here's some random text" > somefile.txt

python3 -c '
with open("somefile.txt") as f:
print(len(f.read()))

import sys
print(sys.argv)'


python3 - << EOF
import sys

print("Here's another way to do it, without restrictions on quotes")
print(sys.argv)
EOF
$ ./multiline_python_bash_script.sh 
(-1+1.2246467991473532e-16j)
['-c']
24
['-c']
Here's another way to do it, without restrictions on quotes
['-']
$ python3 -c "
> print('Interactive test:')
> print('Multi-line works')
> "
Interactive test:
Multi-line works



None of these options is particularly *pretty*, but if it's at the point the 
ugliness bothers you it should probably be its own file to be executed :).  On 
the other hand, none of these options really works on Windows, as far as I know.

--
nosy: +zach.ware

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40568] Modify -c command-line option to accept multiple inputs

2020-05-08 Thread Batuhan Taskaya


Batuhan Taskaya  added the comment:

@rhettinger can you clarify how does this arguments act on argv? Should they be 
hidden like the first argument, or should they remain visible as a passing 
argument? 
 $ python -c 'import sys;print(sys.argv)'   
['-c']

 $ python -c 'import sys;print(sys.argv)' 'print("another")' 'print("another1")'
['-c', 'print("another")', 'print("another1")']

--
nosy: +BTaskaya

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40568] Modify -c command-line option to accept multiple inputs

2020-05-08 Thread Raymond Hettinger


New submission from Raymond Hettinger :

It would be nice to write this:

$ python -c 'from math import *' 'print(e**(1j * pi))'

Instead of this:

$ python -c 'from math import *; print(e**(1j * pi))'
(-1+1.22464679915e-16j)

That would also make it possible input an indented block:

$ python -c 'with open("somefile.txt") as f:'  '  s = f.read()' '  
print(len(s))'

This feature would be especially useful in bash scripts.

FWIW, the timeit module already supports this convenience:

$ python -m timeit -s 'from math import sqrt' -s 'x = 5' 'y = x ** 2' 'z = 
sqrt(y)'
1000 loops, best of 3: 0.0819 usec per loop

--
components: Interpreter Core
messages: 368454
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Modify -c command-line option to accept multiple inputs
type: enhancement
versions: Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com